Skip to content

Commit

Permalink
Return hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyang-sliver committed Jul 25, 2022
1 parent 6847bd2 commit 0e88409
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 2 additions & 4 deletions common/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package common

import (
"math/big"

"github.com/thetatoken/theta/blockchain"
"github.com/thetatoken/theta/common"
tcommon "github.com/thetatoken/theta/common"
Expand All @@ -21,12 +19,12 @@ type EthGetTransactionResult struct {
From tcommon.Address `json:"from"`
To *tcommon.Address `json:"to"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice *big.Int `json:"gasPrice"`
GasPrice string `json:"gasPrice"`
TxHash tcommon.Hash `json:"hash"`
Nonce hexutil.Uint64 `json:"nonce"`
Input string `json:"input"`
TransactionIndex hexutil.Uint64 `json:"transactionIndex"`
Value *big.Int `json:"value"`
Value string `json:"value"`
V hexutil.Uint64 `json:"v"` //ECDSA recovery id
R tcommon.Hash `json:"r"` //ECDSA signature r
S tcommon.Hash `json:"s"` //ECDSA signature s
Expand Down
4 changes: 2 additions & 2 deletions rpc/ethrpc/eth_get_block_by_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func GetBlockFromTRPCResult(chainID *big.Int, rpcRes *rpcc.RPCResponse, rpcErr e
} else {
ethTx.To = &scTx.To.Address
}
ethTx.GasPrice = scTx.GasPrice
ethTx.GasPrice = "0x" + scTx.GasPrice.Text(16)
ethTx.Gas = hexutil.Uint64(scTx.GasLimit)
ethTx.Value = scTx.From.Coins.TFuelWei
ethTx.Value = "0x" + scTx.From.Coins.TFuelWei.Text(16)
ethTx.Input = "0x" + hex.EncodeToString(scTx.Data)
sigData := scTx.From.Signature.ToBytes()
ethTx.Nonce = hexutil.Uint64(scTx.From.Sequence) - 1 // off-by-one: Ethereum's account nonce starts from 0, while Theta's account sequnce starts from 1
Expand Down
6 changes: 3 additions & 3 deletions rpc/ethrpc/eth_get_transaction_by_block_hash_and_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func GetIndexedTransactionFromBlock(rpcRes *rpcc.RPCResponse, rpcErr error, txIn
} else {
result.To = &tx.To.Address
}
result.GasPrice = tx.GasPrice
result.GasPrice = "0x" + tx.GasPrice.Text(16)
result.Gas = hexutil.Uint64(tx.GasLimit)
result.Value = tx.From.Coins.TFuelWei
result.Value = "0x" + tx.From.Coins.TFuelWei.Text(16)
result.Input = tx.Data.String()
result.Nonce = hexutil.Uint64(tx.From.Sequence) - 1 // off-by-one: Ethereum's account nonce starts from 0, while Theta's account sequnce starts from 1
data := tx.From.Signature.ToBytes()
Expand All @@ -70,7 +70,7 @@ func GetIndexedTransactionFromBlock(rpcRes *rpcc.RPCResponse, rpcErr error, txIn
result.To = &tx.Outputs[0].Address
}
result.Gas = hexutil.Uint64(tx.Fee.TFuelWei.Uint64())
result.Value = tx.Inputs[0].Coins.TFuelWei
result.Value = "0x" + tx.Inputs[0].Coins.TFuelWei.Text(16)
result.Nonce = hexutil.Uint64(tx.Inputs[0].Sequence) - 1 // off-by-one: Ethereum's account nonce starts from 0, while Theta's account sequnce starts from 1
data := tx.Inputs[0].Signature.ToBytes()
GetRSVfromSignature(data, &result)
Expand Down
10 changes: 7 additions & 3 deletions rpc/ethrpc/eth_get_transaction_by_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (e *EthRPCService) GetTransactionByHash(ctx context.Context, hashStr string
for i := 0; i < maxRetry; i++ { // It might take some time for a block to be finalized, retry a few times
rpcRes, rpcErr := client.Call("theta.GetTransaction", trpc.GetTransactionArgs{Hash: hashStr})

if rpcErr != nil {
logger.Warnf("eth_getTransactionByHash failed, err: %v", rpcErr)
}

parse := func(jsonBytes []byte) (interface{}, error) {
trpcResult := trpc.GetTransactionResult{}
json.Unmarshal(jsonBytes, &trpcResult)
Expand Down Expand Up @@ -90,7 +94,7 @@ func (e *EthRPCService) GetTransactionByHash(ctx context.Context, hashStr string
result.To = &tx.Outputs[0].Address
}
result.Gas = hexutil.Uint64(tx.Fee.TFuelWei.Uint64())
result.Value = tx.Inputs[0].Coins.TFuelWei
result.Value = "0x" + tx.Inputs[0].Coins.TFuelWei.Text(16)
data := tx.Inputs[0].Signature.ToBytes()
result.Nonce = hexutil.Uint64(tx.Inputs[0].Sequence) - 1 // off-by-one: Ethereum's account nonce starts from 0, while Theta's account sequnce starts from 1
GetRSVfromSignature(data, &result)
Expand All @@ -103,9 +107,9 @@ func (e *EthRPCService) GetTransactionByHash(ctx context.Context, hashStr string
} else {
result.To = &tx.To.Address
}
result.GasPrice = tx.GasPrice
result.GasPrice = "0x" + tx.GasPrice.Text(16)
result.Gas = hexutil.Uint64(tx.GasLimit)
result.Value = tx.From.Coins.TFuelWei
result.Value = "0x" + tx.From.Coins.TFuelWei.Text(16)
//result.Input = tx.Data.String()
result.Input = "0x" + hex.EncodeToString(tx.Data)
data := tx.From.Signature.ToBytes()
Expand Down

0 comments on commit 0e88409

Please sign in to comment.