Skip to content

Commit

Permalink
Merge pull request #100 from 0xcregis/feature-op
Browse files Browse the repository at this point in the history
Feature op
  • Loading branch information
sunjiangjun authored Feb 24, 2024
2 parents f90204d + 2e95664 commit a64ad47
Show file tree
Hide file tree
Showing 24 changed files with 607 additions and 134 deletions.
9 changes: 3 additions & 6 deletions blockchain/chain/bnb/bnb.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ func (e *Bnb) Subscribe(host string, token string) (string, error) {
}

func (e *Bnb) UnSubscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func NewChainClient() blockchain.ChainConn {
Expand All @@ -274,13 +273,11 @@ func NewNFTClient() blockchain.NFT {
}

func (e *Bnb) SendRequestToChainByHttp(host string, token string, query string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (e *Bnb) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *Bnb) SendRequestToChain(host string, token string, query string) (string, error) {
Expand Down
11 changes: 4 additions & 7 deletions blockchain/chain/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (e *Btc) Subscribe(host string, token string) (string, error) {
}

func (e *Btc) UnSubscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func NewChainClient() blockchain.ChainConn {
Expand All @@ -56,13 +55,11 @@ func NewChainClient() blockchain.ChainConn {
}

func (e *Btc) SendRequestToChainByHttp(host string, token string, query string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (e *Btc) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *Btc) SendRequestToChain(host string, token string, query string) (string, error) {
Expand Down Expand Up @@ -122,5 +119,5 @@ func (e *Btc) SendRequestToChain(host string, token string, query string) (strin
}

func (e *Btc) GetToken20(host string, key string, contractAddress string, userAddress string) (map[string]interface{}, error) {
return nil, nil
return nil, fmt.Errorf("not implement the method")
}
6 changes: 2 additions & 4 deletions blockchain/chain/ether/ether.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,11 @@ func NewNFTClient() blockchain.NFT {
}

func (e *Ether) SendRequestToChainByHttp(host string, token string, query string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (e *Ether) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *Ether) SendRequestToChain(host string, token string, query string) (string, error) {
Expand Down
17 changes: 6 additions & 11 deletions blockchain/chain/filecoin/filecoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ type Filecoin struct {
}

func (e *Filecoin) GetToken721(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *Filecoin) GetToken1155(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *Filecoin) Subscribe(host string, token string) (string, error) {
Expand All @@ -39,22 +37,19 @@ func (e *Filecoin) Subscribe(host string, token string) (string, error) {
}

func (e *Filecoin) UnSubscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func NewChainClient() blockchain.ChainConn {
return &Filecoin{}
}

func (e *Filecoin) SendRequestToChainByHttp(host string, token string, query string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (e *Filecoin) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *Filecoin) SendRequestToChain(host string, token string, query string) (string, error) {
Expand Down Expand Up @@ -91,5 +86,5 @@ func (e *Filecoin) SendRequestToChain(host string, token string, query string) (
}

func (e *Filecoin) GetToken20(host string, key string, contractAddress string, userAddress string) (map[string]interface{}, error) {
return nil, nil
return nil, fmt.Errorf("not implement the method")
}
9 changes: 3 additions & 6 deletions blockchain/chain/polygonpos/polygon_pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ func (e *PolygonPos) Subscribe(host string, token string) (string, error) {
}

func (e *PolygonPos) UnSubscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func NewChainClient() blockchain.ChainConn {
Expand All @@ -274,13 +273,11 @@ func NewNFTClient() blockchain.NFT {
}

func (e *PolygonPos) SendRequestToChainByHttp(host string, token string, query string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (e *PolygonPos) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *PolygonPos) SendRequestToChain(host string, token string, query string) (string, error) {
Expand Down
82 changes: 71 additions & 11 deletions blockchain/chain/tron/tron.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ type Tron struct {
}

func (t *Tron) GetToken721(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (t *Tron) GetToken1155(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (t *Tron) Subscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (t *Tron) UnSubscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func NewChainClient() blockchain.ChainConn {
Expand Down Expand Up @@ -111,6 +107,7 @@ func (t *Tron) SendRequestToChainByHttp(host string, token string, query string)
}

func (t *Tron) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//https://api.trongrid.io/wallet/triggerconstantcontract
mp := make(map[string]interface{}, 2)

if !strings.HasPrefix(userAddress, "0x41") && !strings.HasPrefix(userAddress, "41") {
Expand Down Expand Up @@ -145,6 +142,16 @@ func (t *Tron) GetToken20ByHttp(host string, token string, contractAddress strin
return nil, errors.New("contract is error")
}

name, err := t.GetTokenNameByHttp(host, token, contractAddress, userAddress)
if err == nil {
mp["name"] = name
}

symbol, err := t.GetTokenSymbolByHttp(host, token, contractAddress, userAddress)
if err == nil {
mp["symbol"] = symbol
}

return mp, nil
}

Expand Down Expand Up @@ -200,13 +207,66 @@ func (t *Tron) GetTokenBalanceByHttp2(host string, token string, contractAddress
//log.Println(resp)
r := gjson.Parse(resp).Get("constant_result")
if r.Exists() {
balance, _ := strconv.ParseInt(r.Array()[0].String(), 16, 64)
return fmt.Sprintf("%v", balance), nil
balance := r.Array()[0].String()
b, err := util.ParseTRC20NumericProperty(balance)
if err != nil {
return "", err
}
//balance, _ := strconv.ParseInt(r.Array()[0].String(), 16, 64)
return fmt.Sprintf("%v", b.Int64()), nil
}

return "", errors.New("no data")
}

func (t *Tron) GetTokenNameByHttp(host string, token string, contractAddress string, userAddress string) (string, error) {
//var query string
query := `
{
"owner_address": "%v",
"contract_address": "%v",
"function_selector": "name()"
}
`
query = fmt.Sprintf(query, userAddress, contractAddress)
resp, err := t.SendRequestToChainByHttp(host, token, query)
if err != nil {
return "", err
}
//log.Println(resp)
r := gjson.Parse(resp).Get("constant_result")
if r.Exists() {
name := r.Array()[0].String()
return util.ParseTRC20StringProperty(name)
}

return "", errors.New("no data")
}

func (t *Tron) GetTokenSymbolByHttp(host string, token string, contractAddress string, userAddress string) (string, error) {
//var query string
query := `
{
"owner_address": "%v",
"contract_address": "%v",
"function_selector": "symbol()"
}
`
query = fmt.Sprintf(query, userAddress, contractAddress)
resp, err := t.SendRequestToChainByHttp(host, token, query)
if err != nil {
return "", err
}
//log.Println(resp)
r := gjson.Parse(resp).Get("constant_result")
if r.Exists() {
symbol := r.Array()[0].String()
return util.ParseTRC20StringProperty(symbol)
}

return "", errors.New("no data")
}

func (t *Tron) GetToken20(host string, key string, contractAddress string, userAddress string) (map[string]interface{}, error) {
return nil, nil
return nil, fmt.Errorf("not implement the method")
}
16 changes: 6 additions & 10 deletions blockchain/chain/xrp/xrp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ type XRP struct {
}

func (e *XRP) GetToken721(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *XRP) GetToken1155(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
//TODO implement me
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *XRP) Subscribe(host string, token string) (string, error) {
Expand All @@ -39,21 +37,19 @@ func (e *XRP) Subscribe(host string, token string) (string, error) {
}

func (e *XRP) UnSubscribe(host string, token string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func NewChainClient() blockchain.ChainConn {
return &XRP{}
}

func (e *XRP) SendRequestToChainByHttp(host string, token string, query string) (string, error) {
//TODO implement me
panic("implement me")
return "", fmt.Errorf("not implement the method")
}

func (e *XRP) GetToken20ByHttp(host string, token string, contractAddress string, userAddress string) (map[string]interface{}, error) {
panic("implement me")
return nil, fmt.Errorf("not implement the method")
}

func (e *XRP) SendRequestToChain(host string, token string, query string) (string, error) {
Expand Down Expand Up @@ -92,5 +88,5 @@ func (e *XRP) SendRequestToChain(host string, token string, query string) (strin
}

func (e *XRP) GetToken20(host string, key string, contractAddress string, userAddress string) (map[string]interface{}, error) {
return nil, nil
return nil, fmt.Errorf("not implement the method")
}
22 changes: 11 additions & 11 deletions blockchain/service/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,40 @@ type Btc struct {
}

func (e *Btc) Token(chainCode int64, contractAddr string, abi string, eip string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) GetCode(chainCode int64, address string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) GetAddressType(chainCode int64, address string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) SubscribePendingTx(chainCode int64, receiverCh chan string, sendCh chan string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

// SubscribeLogs {"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["logs", {"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}
func (e *Btc) SubscribeLogs(chainCode int64, address string, topics []string, receiverCh chan string, sendCh chan string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) UnSubscribe(chainCode int64, subId string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) GetBlockReceiptByBlockNumber(chainCode int64, number string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) GetBlockReceiptByBlockHash(chainCode int64, hash string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) GetTransactionReceiptByHash(chainCode int64, hash string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) GetBlockByHash(chainCode int64, hash string, flag bool) (string, error) {
Expand Down Expand Up @@ -171,11 +171,11 @@ func (e *Btc) Balance(chainCode int64, address string, tag string) (string, erro
}

func (e *Btc) TokenBalance(chainCode int64, address string, contractAddr string, abi string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) Nonce(chainCode int64, address string, tag string) (string, error) {
return "", nil
return "", fmt.Errorf("blockchain:%v,the method has not been implemented", chainCode)
}

func (e *Btc) LatestBlock(chainCode int64) (string, error) {
Expand Down
Loading

0 comments on commit a64ad47

Please sign in to comment.