Add EVM Client to return tx hash on failied EVM tx.
@@ -405,3 +405,54 @@ func (c *DAppChainRPCClient) CommitCallTx(
}
return c.CommitTx(signer, tx)
}
+
+type EVMDAppChainRPCClient struct {
+ DAppChainRPCClient
+}
+
+func NewEVMDAppChainRPCClient(chainID, writeURI, readURI string) *EVMDAppChainRPCClient {
+ return &EVMDAppChainRPCClient{*NewDAppChainRPCClient(chainID, writeURI, readURI)}
+}
+
+func (c *EVMDAppChainRPCClient) CommitTx(signer auth.Signer, tx proto.Message) ([]byte, error) {
+ nonce, err := c.GetNonce(signer)
+ if err != nil {
+ return nil, err
+ }
+ txBytes, err := proto.Marshal(tx)
+ if err != nil {
+ return nil, err
+ }
+ nonceTxBytes, err := proto.Marshal(&auth.NonceTx{
+ Inner: txBytes,
+ Sequence: nonce + 1,
+ })
+ if err != nil {
+ return nil, err
+ }
+ signedTxBytes, err := proto.Marshal(auth.SignTx(signer, nonceTxBytes))
+ if err != nil {
+ return nil, err
+ }
+ params := map[string]interface{}{
+ "tx": signedTxBytes,
+ }
+ var r BroadcastTxCommitResult
+ if err = c.txClient.Call("broadcast_tx_commit", params, c.getNextRequestID(), &r); err != nil {
+ return nil, err
+ }
+ if r.CheckTx.Code != 0 {
+ if len(r.CheckTx.Error) != 0 {
+ return r.CheckTx.Data, errors.New(r.CheckTx.Error)
+ }
+ return r.CheckTx.Data, errors.New("CheckTx failed")
+ }
+ if r.DeliverTx.Code != 0 {
+ if len(r.DeliverTx.Error) != 0 {
+ return r.DeliverTx.Data, errors.New(r.DeliverTx.Error)
+ }
+ return r.DeliverTx.Data, errors.New("DeliverTx failed")
+ }
+
+ return r.DeliverTx.Data, nil
+}
