Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query shard tx state #1033

Merged
merged 21 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cmd/info_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ var InfoCommand = cli.Command{
utils.RPCPortFlag,
},
},
{
Action: txState,
Name: "shardtxstate",
Usage: "Display transaction state",
ArgsUsage: "<txhash>",
Description: `Display status of transaction.`,
Flags: []cli.Flag{
utils.RPCPortFlag,
},
},
{
Action: curBlockHeight,
Name: "curblockheight",
Expand Down Expand Up @@ -155,6 +165,34 @@ func txStatus(ctx *cli.Context) error {
return nil
}

func txState(ctx *cli.Context) error {
SetRpcPort(ctx)
if ctx.NArg() < 1 {
PrintErrorMsg("Missing argument. TxHash expected.")
cli.ShowSubcommandHelp(ctx)
return nil
}
txHash := ctx.Args().First()
var notifyId string
var isHasNotifyId bool
if ctx.NArg() > 1 {
args := ctx.Args().Tail()
notifyId = args[0]
isHasNotifyId = true
}
txState, err := utils.GetShardTxState(txHash, notifyId, isHasNotifyId)
if err != nil {
return fmt.Errorf("GetShardTxState error:%s", err)
}
if string(txState) == "null" {
PrintInfoMsg("Cannot get SmartContractEvent by TxHash:%s.", txHash)
return nil
}
PrintInfoMsg("Transaction states:")
PrintJsonData(txState)
return nil
}

func curBlockHeight(ctx *cli.Context) error {
SetRpcPort(ctx)
count, err := utils.GetBlockCount()
Expand Down
17 changes: 17 additions & 0 deletions cmd/utils/ont.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,23 @@ func GetSmartContractEventInfo(txHash string) ([]byte, error) {
return nil, ontErr.Error
}

func GetShardTxState(txHash string, notifyId string, isHasNotifyId bool) ([]byte, error) {
params := make([]interface{}, 0)
params = append(params, txHash)
if isHasNotifyId {
params = append(params, notifyId)
}
data, ontErr := sendRpcRequest("getshardtxstate", params)
if ontErr == nil {
return data, nil
}
switch ontErr.ErrorCode {
case ERROR_INVALID_PARAMS:
return nil, fmt.Errorf("invalid TxHash:%s", txHash)
}
return nil, ontErr.Error
}

func GetRawTransaction(txHash string) ([]byte, error) {
data, ontErr := sendRpcRequest("getrawtransaction", []interface{}{txHash, 1})
if ontErr == nil {
Expand Down
16 changes: 11 additions & 5 deletions http/base/rpc/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,21 @@ func GetShardTxState(params []interface{}) map[string]interface{} {
default:
return responsePack(berr.INVALID_PARAMS, "")
}
var notifyId uint32
var ok bool
var notifyId uint64
var isHasNotify bool
if len(params) > 1 {
notifyId, ok = params[1].(uint32)
if !ok {
switch str := params[1].(type) {
case string:
notifyId, err = strconv.ParseUint(str, 10, 64)
if err != nil {
return responsePack(berr.INVALID_PARAMS, "")
}
isHasNotify = true
default:
return responsePack(berr.INVALID_PARAMS, "")
}
}
value, err := bactor.GetShardTxState(txHash, notifyId, ok)
value, err := bactor.GetShardTxState(txHash, uint32(notifyId), isHasNotify)
if err != nil {
if err == scom.ErrNotFound {
return responseSuccess(nil)
Expand Down