Skip to content

Commit

Permalink
add method to get raw transaction data from mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy committed Jun 3, 2024
1 parent 3559cad commit 299f98f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 61 deletions.
5 changes: 3 additions & 2 deletions http/base/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type TXNAttrInfo struct {

type TXNEntryInfo struct {
State []TXNAttrInfo // the result from each validator
Raw string
}

func GetLogEvent(obj *event.LogEventArgs) (map[string]bool, LogEventArgs) {
Expand Down Expand Up @@ -610,7 +611,7 @@ func GetBlockTransactions(block *types.Block) interface{} {
return b
}

//NewNativeInvokeTransaction return native contract invoke transaction
// NewNativeInvokeTransaction return native contract invoke transaction
func NewNativeInvokeTransaction(gasPirce, gasLimit uint64, contractAddress common.Address, version byte,
method string, params []interface{}) (*types.MutableTransaction, error) {
invokeCode, err := cutils.BuildNativeInvokeCode(contractAddress, version, method, params)
Expand Down Expand Up @@ -643,7 +644,7 @@ func NewSmartContractTransaction(gasPrice, gasLimit uint64, invokeCode []byte) (
return tx, nil
}

//BuildNeoVMInvokeCode build NeoVM Invoke code for params
// BuildNeoVMInvokeCode build NeoVM Invoke code for params
func BuildNeoVMInvokeCode(smartContractAddress common.Address, params []interface{}) ([]byte, error) {
builder := neovm.NewParamsBuilder(new(bytes.Buffer))
err := cutils.BuildNeoVMParam(builder, params)
Expand Down
55 changes: 28 additions & 27 deletions http/base/rest/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package rest

import (
"encoding/hex"
"strconv"

"github.com/ontio/ontology/common"
Expand Down Expand Up @@ -54,7 +55,7 @@ func GetNetworkId(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get connection node count
// get connection node count
func GetConnectionCount(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
count := bactor.GetConnectionCnt()
Expand All @@ -72,15 +73,15 @@ func GetNodeSyncStatus(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get block height
// get block height
func GetBlockHeight(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
height := bactor.GetCurrentBlockHeight()
resp["Result"] = height
return resp
}

//get block hash by height
// get block hash by height
func GetBlockHash(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
param, ok := cmd["Height"].(string)
Expand Down Expand Up @@ -116,7 +117,7 @@ func getBlock(hash common.Uint256, getTxBytes bool) (interface{}, int64) {
return bcomn.GetBlockInfo(block), berr.SUCCESS
}

//get block by hash
// get block by hash
func GetBlockByHash(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
str := cmd["Hash"].(string)
Expand All @@ -136,7 +137,7 @@ func GetBlockByHash(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get block height by transaction hash
// get block height by transaction hash
func GetBlockHeightByTxHash(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
str, ok := cmd["Hash"].(string)
Expand All @@ -158,7 +159,7 @@ func GetBlockHeightByTxHash(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get block transaction hashes by height
// get block transaction hashes by height
func GetBlockTxsByHeight(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)

Expand All @@ -183,7 +184,7 @@ func GetBlockTxsByHeight(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get block by height
// get block by height
func GetBlockByHeight(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)

Expand Down Expand Up @@ -215,7 +216,7 @@ func GetBlockByHeight(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get transaction by hash
// get transaction by hash
func GetTransactionByHash(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)

Expand Down Expand Up @@ -247,7 +248,7 @@ func GetTransactionByHash(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//send raw transaction
// send raw transaction
func SendRawTransaction(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)

Expand Down Expand Up @@ -291,7 +292,7 @@ func SendRawTransaction(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get smartcontract event by height
// get smartcontract event by height
func GetSmartCodeEventTxsByHeight(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)

Expand Down Expand Up @@ -323,7 +324,7 @@ func GetSmartCodeEventTxsByHeight(cmd map[string]interface{}) map[string]interfa
return resp
}

//get smartcontract event by transaction hash
// get smartcontract event by transaction hash
func GetSmartCodeEventByTxHash(cmd map[string]interface{}) map[string]interface{} {
if !config.DefConfig.Common.EnableEventLog {
return ResponsePack(berr.INVALID_METHOD)
Expand Down Expand Up @@ -354,7 +355,7 @@ func GetSmartCodeEventByTxHash(cmd map[string]interface{}) map[string]interface{
return resp
}

//get contract state
// get contract state
func GetContractState(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
str, ok := cmd["Hash"].(string)
Expand Down Expand Up @@ -382,7 +383,7 @@ func GetContractState(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get storage from contract
// get storage from contract
func GetStorage(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
str, ok := cmd["Hash"].(string)
Expand All @@ -409,7 +410,7 @@ func GetStorage(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get balance of address
// get balance of address
func GetBalance(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
addrBase58, ok := cmd["Addr"].(string)
Expand All @@ -428,7 +429,7 @@ func GetBalance(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get balance of address
// get balance of address
func GetBalanceV2(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
addrBase58, ok := cmd["Addr"].(string)
Expand All @@ -447,7 +448,7 @@ func GetBalanceV2(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get merkle proof by transaction hash
// get merkle proof by transaction hash
func GetMerkleProof(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
str, ok := cmd["Hash"].(string)
Expand Down Expand Up @@ -488,7 +489,7 @@ func GetMerkleProof(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get avg gas price in block
// get avg gas price in block
func GetGasPrice(cmd map[string]interface{}) map[string]interface{} {
gasPrice, height, err := bcomn.GetGasPrice()
if err != nil {
Expand All @@ -500,7 +501,7 @@ func GetGasPrice(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get allowance
// get allowance
func GetAllowance(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
asset, ok := cmd["Asset"].(string)
Expand Down Expand Up @@ -531,7 +532,7 @@ func GetAllowance(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get allowance
// get allowance
func GetAllowanceV2(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
asset, ok := cmd["Asset"].(string)
Expand Down Expand Up @@ -562,7 +563,7 @@ func GetAllowanceV2(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get unbound ong
// get unbound ong
func GetUnboundOng(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
toAddrStr, ok := cmd["Addr"].(string)
Expand All @@ -582,7 +583,7 @@ func GetUnboundOng(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get grant ong
// get grant ong
func GetGrantOng(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
toAddrStr, ok := cmd["Addr"].(string)
Expand All @@ -601,23 +602,23 @@ func GetGrantOng(cmd map[string]interface{}) map[string]interface{} {
return resp
}

//get memory pool transaction count
// get memory pool transaction count
func GetMemPoolTxCount(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
count := bactor.GetTxnCount()
resp["Result"] = count
return resp
}

//get memory pool transaction hash list
// get memory pool transaction hash list
func GetMemPoolTxHashList(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
txHashList := bactor.GetTxnHashList()
resp["Result"] = txHashList
return resp
}

//get memory poll transaction state
// get memory poll transaction state
func GetMemPoolTxState(cmd map[string]interface{}) map[string]interface{} {
resp := ResponsePack(berr.SUCCESS)
str, ok := cmd["Hash"].(string)
Expand All @@ -632,10 +633,10 @@ func GetMemPoolTxState(cmd map[string]interface{}) map[string]interface{} {
if err != nil {
return ResponsePack(berr.UNKNOWN_TRANSACTION)
}
attrs := []bcomn.TXNAttrInfo{}
var attrs []bcomn.TXNAttrInfo
for _, t := range txEntry.Attrs {
attrs = append(attrs, bcomn.TXNAttrInfo{t.Height, int(t.Type), int(t.ErrCode)})
attrs = append(attrs, bcomn.TXNAttrInfo{Height: t.Height, Type: int(t.Type), ErrCode: int(t.ErrCode)})
}
resp["Result"] = bcomn.TXNEntryInfo{attrs}
resp["Result"] = bcomn.TXNEntryInfo{State: attrs, Raw: hex.EncodeToString(txEntry.Tx.ToArray())}
return resp
}
Loading

0 comments on commit 299f98f

Please sign in to comment.