Skip to content

Commit

Permalink
Update sdk and abi
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyachi committed Nov 16, 2022
1 parent d65782c commit c6ed2c3
Show file tree
Hide file tree
Showing 6 changed files with 10,510 additions and 3 deletions.
3,750 changes: 3,750 additions & 0 deletions abi/mintable_erc20_abi/mintable_erc20_abi.go

Large diffs are not rendered by default.

6,696 changes: 6,696 additions & 0 deletions abi/nft_mapping_abi/nft_mapping_abi.go

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions chains/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"

erc20 "github.com/polynetwork/bridge-common/abi/mintable_erc20_abi"
nftmapping "github.com/polynetwork/bridge-common/abi/nft_mapping_abi"
"github.com/polynetwork/bridge-common/chains"
"github.com/polynetwork/bridge-common/log"
"github.com/polynetwork/bridge-common/util"
Expand All @@ -54,13 +56,15 @@ func (c *Client) Address() string {
return c.address
}

func (c *Client) GetHeader(height uint64) (header Header, err error){
func (c *Client) GetHeader(height uint64) (header Header, err error) {
head := make(json.RawMessage, 0)
err = c.Rpc.CallContext(context.Background(), &head, "eth_getBlockByNumber", util.BlockNumArg(height), false)
if err == nil && len(head) == 0 {
err = ethereum.NotFound
}
if err != nil { return }
if err != nil {
return
}
header = Header(head)
if height == 0 {
_, err = header.GetHeight()
Expand Down Expand Up @@ -148,6 +152,31 @@ func (c *Client) Confirm(hash common.Hash, blocks uint64, count int) (height, co
return
}

func (c *Client) GetBalance(token, owner string) (balance *big.Int, err error) {
tokenAddress := common.HexToAddress(token)
ownerAddr := common.HexToAddress(owner)
if token == "0000000000000000000000000000000000000000" {
var result hexutil.Big
err = c.Rpc.CallContext(context.Background(), &result, "eth_getBalance", "0x"+owner, "latest")
balance = (*big.Int)(&result)
} else {
var contract *erc20.ERC20Extended
contract, err = erc20.NewERC20Mintable(tokenAddress, c)
if err == nil {
balance, err = contract.BalanceOf(nil, ownerAddr)
}
}
return
}

func (c *Client) GetNFTOwner(asset string, tokenId int64) (owner common.Address, err error) {
cm, err := nftmapping.NewCrossChainNFTMapping(common.HexToAddress(asset), c)
if err != nil {
return common.Address{}, err
}
return cm.OwnerOf(nil, big.NewInt(tokenId))
}

type SDK struct {
*chains.ChainSDK
nodes []*Client
Expand Down
16 changes: 16 additions & 0 deletions chains/neo/neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package neo

import (
"fmt"
"github.com/joeqian10/neo-gogogo/nep5"
"math/big"
"time"

"github.com/joeqian10/neo-gogogo/helper"
Expand Down Expand Up @@ -80,6 +82,20 @@ func (c *Client) GetPolyEpochHeight(ccm string, chainId uint64) (height uint64,
return
}

func (c *Client) GetBalance(token, owner string) (balance *big.Int, err error) {
scriptHash, err := helper.UInt160FromString(token)
if err != nil {
return nil, err
}
nep5Helper := nep5.NewNep5Helper(scriptHash, c.address)
addrHash, err := helper.UInt160FromString(owner)
if err != nil {
return nil, err
}
amount, err := nep5Helper.BalanceOf(addrHash)
return new(big.Int).SetUint64(amount), nil
}

type SDK struct {
*chains.ChainSDK
nodes []*Client
Expand Down
16 changes: 16 additions & 0 deletions chains/neo3/neo3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package neo3

import (
"fmt"
"github.com/joeqian10/neo3-gogogo/helper"
"github.com/joeqian10/neo3-gogogo/nep17"
"math/big"
"time"

"github.com/joeqian10/neo3-gogogo/rpc"
Expand Down Expand Up @@ -53,6 +56,19 @@ func (c *Client) GetLatestHeight() (uint64, error) {
return uint64(res.Result), nil
}

func (c *Client) GetBalance(token, owner string) (balance *big.Int, err error) {
scriptHash, err := helper.UInt160FromString(token)
if err != nil {
return nil, err
}
nep17Helper := nep17.NewNep17Helper(scriptHash, c)
addrHash, err := helper.UInt160FromString(owner)
if err != nil {
return nil, err
}
return nep17Helper.BalanceOf(addrHash)
}

type SDK struct {
*chains.ChainSDK
nodes []*Client
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/ontio/ontology v1.11.1-0.20200812075204-26cf1fa5dd47
github.com/ontio/ontology-crypto v1.2.1 // indirect
github.com/ontio/ontology-go-sdk v1.11.4
github.com/portto/aptos-go-sdk v0.0.0-20220923072903-ff01c1b3e3dc
github.com/portto/aptos-go-sdk v0.0.0-20221025115549-5c74acafa193
github.com/prometheus/tsdb v0.9.1 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/rs/cors v1.7.0
Expand Down

0 comments on commit c6ed2c3

Please sign in to comment.