Skip to content

Commit

Permalink
support getCrossChainMsg and getCrossStateProof through rpc client, u…
Browse files Browse the repository at this point in the history
…pgrade ontology to v1.10.0, ontology-crypto to v1.0.9 (#116)
  • Loading branch information
skyinglyh1 authored Jul 23, 2020
1 parent 9c5ec69 commit 8ba4556
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
25 changes: 25 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ontio/ontology/common"
"github.com/ontio/ontology/core/payload"
"github.com/ontio/ontology/core/types"
bc "github.com/ontio/ontology/http/base/common"
"sync/atomic"
"time"
)
Expand Down Expand Up @@ -237,6 +238,30 @@ func (this *ClientMgr) GetMerkleProof(txHash string) (*sdkcom.MerkleProof, error
return utils.GetMerkleProof(data)
}

func (this *ClientMgr) GetCrossStatesProof(height uint32, key []byte) (*bc.CrossStatesProof, error) {
client := this.getClient()
if client == nil {
return nil, fmt.Errorf("don't have available client of ontology")
}
data, err := client.getCrossStatesProof(this.getNextQid(), height, key)
if err != nil {
return nil, err
}
return utils.GetCrossStatesProof(data)
}

func (this *ClientMgr) GetCrossChainMsg(height uint32) (string, error) {
client := this.getClient()
if client == nil {
return "", fmt.Errorf("don't have available client of ontology")
}
data, err := client.getCrossChainMsg(this.getNextQid(), height)
if err != nil {
return "", err
}
return utils.GetCrossChainMsg(data)
}

func (this *ClientMgr) GetMemPoolTxState(txHash string) (*sdkcom.MemPoolTxState, error) {
client := this.getClient()
if client == nil {
Expand Down
4 changes: 4 additions & 0 deletions client/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type OntologyClient interface {
getSmartContractEventByBlock(qid string, blockHeight uint32) ([]byte, error)
getStorage(qid, contractAddress string, key []byte) ([]byte, error)
getMerkleProof(qid, txHash string) ([]byte, error)
getCrossStatesProof(qid string, height uint32, key []byte) ([]byte, error)
getCrossChainMsg(qid string, height uint32) ([]byte, error)
getMemPoolTxState(qid, txHash string) ([]byte, error)
getMemPoolTxCount(qid string) ([]byte, error)
sendRawTransaction(qid string, tx *types.Transaction, isPreExec bool) ([]byte, error)
Expand All @@ -59,6 +61,8 @@ const (
RPC_GET_SMART_CONTRACT = "getcontractstate"
RPC_GET_GENERATE_BLOCK_TIME = "getgenerateblocktime"
RPC_GET_MERKLE_PROOF = "getmerkleproof"
RPC_GET_CROSS_STATES_PROOF = "getcrossstatesproof"
RPC_GET_CROSS_CHAIN_MSG = "getcrosschainmsg"
RPC_GET_NETWORK_ID = "getnetworkid"
RPC_GET_MEM_POOL_TX_COUNT = "getmempooltxcount"
RPC_GET_MEM_POOL_TX_STATE = "getmempooltxstate"
Expand Down
8 changes: 8 additions & 0 deletions client/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func (this RestClient) getMerkleProof(qid, txHash string) ([]byte, error) {
return this.sendRestGetRequest(reqPath)
}

func (this *RestClient) getCrossStatesProof(qid string, height uint32, key []byte) ([]byte, error) {
return nil, fmt.Errorf("getCrossStateProof not supported by RestClient")
}

func (this *RestClient) getCrossChainMsg(qid string, height uint32) ([]byte, error) {
return nil, fmt.Errorf("getCrossChainMsg not supported by RestClient")
}

func (this *RestClient) getMemPoolTxState(qid, txHash string) ([]byte, error) {
reqPath := GET_MEMPOOL_TXSTATE + txHash
return this.sendRestGetRequest(reqPath)
Expand Down
8 changes: 8 additions & 0 deletions client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ func (this *RpcClient) getMerkleProof(qid, txHash string) ([]byte, error) {
return this.sendRpcRequest(qid, RPC_GET_MERKLE_PROOF, []interface{}{txHash})
}

func (this *RpcClient) getCrossStatesProof(qid string, height uint32, key []byte) ([]byte, error) {
return this.sendRpcRequest(qid, RPC_GET_CROSS_STATES_PROOF, []interface{}{height, hex.EncodeToString(key)})
}

func (this *RpcClient) getCrossChainMsg(qid string, height uint32) ([]byte, error) {
return this.sendRpcRequest(qid, RPC_GET_CROSS_CHAIN_MSG, []interface{}{height})
}

func (this *RpcClient) getMemPoolTxState(qid, txHash string) ([]byte, error) {
return this.sendRpcRequest(qid, RPC_GET_MEM_POOL_TX_STATE, []interface{}{txHash})
}
Expand Down
8 changes: 8 additions & 0 deletions client/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,14 @@ func (this *WSClient) getMerkleProof(qid, txHash string) ([]byte, error) {
return this.sendSyncWSRequest(qid, WS_ACTION_GET_MERKLE_PROOF, map[string]interface{}{"Hash": txHash})
}

func (this *WSClient) getCrossStatesProof(qid string, height uint32, key []byte) ([]byte, error) {
return nil, fmt.Errorf("getCrossStateProof not supported by WSClient")
}

func (this *WSClient) getCrossChainMsg(qid string, height uint32) ([]byte, error) {
return nil, fmt.Errorf("getCrossChainMsg not supported by WSClient")
}

func (this *WSClient) getSmartContractEvent(qid, txHash string) ([]byte, error) {
return this.sendSyncWSRequest(qid, WS_ACTION_GET_SMARTCONTRACT_BY_HASH, map[string]interface{}{"Hash": txHash})
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/gorilla/websocket v1.4.1
github.com/itchyny/base58-go v0.1.0
github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b
github.com/ontio/ontology v1.8.2
github.com/ontio/ontology-crypto v1.0.7
github.com/satori/go.uuid v1.2.0
github.com/ontio/ontology v1.10.0
github.com/ontio/ontology-crypto v1.0.9
github.com/stretchr/testify v1.4.0
github.com/tyler-smith/go-bip39 v1.0.2
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
)
19 changes: 19 additions & 0 deletions utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ontio/ontology/common"
"github.com/ontio/ontology/core/payload"
"github.com/ontio/ontology/core/types"
bc "github.com/ontio/ontology/http/base/common"
)

func GetVersion(data []byte) (string, error) {
Expand Down Expand Up @@ -173,6 +174,24 @@ func GetMerkleProof(data []byte) (*sdkcom.MerkleProof, error) {
return proof, nil
}

func GetCrossStatesProof(data []byte) (*bc.CrossStatesProof, error) {
proof := &bc.CrossStatesProof{}
err := json.Unmarshal(data, proof)
if err != nil {
return nil, fmt.Errorf("json.Unmarshal error:%s", err)
}
return proof, nil
}

func GetCrossChainMsg(data []byte) (string, error) {
crossChainMsg := ""
err := json.Unmarshal(data, &crossChainMsg)
if err != nil {
return "", fmt.Errorf("json.Unmarshal error:%s", err)
}
return crossChainMsg, nil
}

func GetBlockTxHashes(data []byte) (*sdkcom.BlockTxHashes, error) {
blockTxHashesStr := &sdkcom.BlockTxHashesStr{}
err := json.Unmarshal(data, &blockTxHashesStr)
Expand Down

0 comments on commit 8ba4556

Please sign in to comment.