Skip to content

Commit 8a27218

Browse files
Frankonlyzjshen14
authored andcommitted
All action support for action hash cmd (#873)
1 parent f0aec56 commit 8a27218

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

cli/ioctl/cmd/action/actionhash.go

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package action
88

99
import (
1010
"context"
11-
"errors"
1211
"fmt"
1312
"strconv"
1413

@@ -100,72 +99,68 @@ func printActionProto(action *iotextypes.Action) (string, error) {
10099
log.L().Error("failed to convert bytes into address", zap.Error(err))
101100
return "", err
102101
}
102+
output := fmt.Sprintf("\nversion: %d ", action.Core.GetVersion()) +
103+
fmt.Sprintf("nonce: %d ", action.Core.GetNonce()) +
104+
fmt.Sprintf("gasLimit: %d ", action.Core.GasLimit) +
105+
fmt.Sprintf("gasPrice: %s Rau\n", action.Core.GasPrice) +
106+
fmt.Sprintf("senderAddress: %s %s\n", senderAddress.String(),
107+
match(senderAddress.String(), "address"))
103108
switch {
104109
case action.Core.GetTransfer() != nil:
105110
transfer := action.Core.GetTransfer()
106-
return fmt.Sprintf("\nversion: %d ", action.Core.GetVersion()) +
107-
fmt.Sprintf("nonce: %d ", action.Core.GetNonce()) +
108-
fmt.Sprintf("gasLimit: %d ", action.Core.GasLimit) +
109-
fmt.Sprintf("gasPrice: %s Rau\n", action.Core.GasPrice) +
110-
fmt.Sprintf("senderAddress: %s %s\n", senderAddress.String(),
111-
match(senderAddress.String(), "address")) +
112-
"transfer: <\n" +
111+
output += "transfer: <\n" +
113112
fmt.Sprintf(" recipient: %s %s\n", transfer.Recipient,
114113
match(transfer.Recipient, "address")) +
115-
fmt.Sprintf(" amount: %s Rau\n", transfer.Amount) +
116-
fmt.Sprintf(" payload: %s\n", transfer.Payload) +
117-
">\n" +
118-
fmt.Sprintf("senderPubKey: %x\n", action.SenderPubKey) +
119-
fmt.Sprintf("signature: %x\n", action.Signature), nil
114+
fmt.Sprintf(" amount: %s Rau\n", transfer.Amount)
115+
if len(transfer.Payload) != 0 {
116+
output += fmt.Sprintf(" payload: %s\n", transfer.Payload)
117+
}
118+
output += ">\n"
120119
case action.Core.GetExecution() != nil:
121120
execution := action.Core.GetExecution()
122-
return fmt.Sprintf("\nversion: %d ", action.Core.GetVersion()) +
123-
fmt.Sprintf("nonce: %d ", action.Core.GetNonce()) +
124-
fmt.Sprintf("gasLimit: %d ", action.Core.GasLimit) +
125-
fmt.Sprintf("gasPrice: %s Rau\n", action.Core.GasPrice) +
126-
fmt.Sprintf("senderAddress: %s %s\n", senderAddress.String(),
127-
match(senderAddress.String(), "address")) +
128-
"execution: <\n" +
121+
output += "execution: <\n" +
129122
fmt.Sprintf(" contract: %s %s\n", execution.Contract,
130-
match(execution.Contract, "address")) +
131-
fmt.Sprintf(" amount: %s Rau\n", execution.Amount) +
132-
fmt.Sprintf(" data: %x\n", execution.Data) +
133-
">\n" +
134-
fmt.Sprintf("senderPubKey: %x\n", action.SenderPubKey) +
135-
fmt.Sprintf("signature: %x\n", action.Signature), nil
136-
case action.Core.GetClaimFromRewardingFund() != nil:
137-
return fmt.Sprintf("\nversion: %d ", action.Core.GetVersion()) +
138-
fmt.Sprintf("nonce: %d ", action.Core.GetNonce()) +
139-
fmt.Sprintf("gasLimit: %d ", action.Core.GasLimit) +
140-
fmt.Sprintf("gasPrice: %s Rau\n", action.Core.GasPrice) +
141-
fmt.Sprintf("senderAddress: %s %s\n", senderAddress.String(),
142-
match(senderAddress.String(), "address")) +
143-
proto.MarshalTextString(action.Core) +
144-
fmt.Sprintf("senderPubKey: %x\n", action.SenderPubKey) +
145-
fmt.Sprintf("signature: %x\n", action.Signature), nil
146-
}
147-
return "", errors.New("action can not match")
123+
match(execution.Contract, "address"))
124+
if execution.Amount != "0" {
125+
output += fmt.Sprintf(" amount: %s Rau\n", execution.Amount)
126+
}
127+
output += fmt.Sprintf(" data: %x\n", execution.Data) + ">\n"
128+
default:
129+
output += proto.MarshalTextString(action.Core)
130+
}
131+
output += fmt.Sprintf("senderPubKey: %x\n", action.SenderPubKey) +
132+
fmt.Sprintf("signature: %x\n", action.Signature)
133+
134+
return output, nil
148135
}
149136

150137
func printReceiptProto(receipt *iotextypes.Receipt) string {
151-
lines := make([]string, 0)
138+
logs := make([]string, 0)
152139
for _, l := range receipt.Logs {
153-
line := fmt.Sprintf("#%d block:%d txHash:%s address:%s data:%s\n",
140+
log := fmt.Sprintf("#%d block:%d txHash:%s address:%s data:%s\n",
154141
l.Index, l.BlockNumber, l.TxnHash, l.Address, l.Data)
155142
for _, t := range l.Topics {
156-
line += fmt.Sprintf(" %s\n", t)
143+
log += fmt.Sprintf(" %s\n", t)
157144
}
158-
lines = append(lines, line)
145+
logs = append(logs, log)
159146
}
160-
return fmt.Sprintf("returnValue: %x\n", receipt.ReturnValue) +
161-
fmt.Sprintf("status: %d %s\n", receipt.Status,
162-
match(strconv.Itoa(int(receipt.Status)), "status")) +
147+
output := ""
148+
if len(receipt.ReturnValue) != 0 {
149+
output += fmt.Sprintf("returnValue: %x\n", receipt.ReturnValue)
150+
}
151+
output += fmt.Sprintf("status: %d %s\n", receipt.Status,
152+
match(strconv.Itoa(int(receipt.Status)), "status")) +
163153
fmt.Sprintf("actHash: %x\n", receipt.ActHash) +
164154
// TODO: blkHash
165-
fmt.Sprintf("gasConsumed: %d\n", receipt.GasConsumed) +
166-
fmt.Sprintf("contractAddress: %s %s\n", receipt.ContractAddress,
167-
match(receipt.ContractAddress, "address")) +
168-
fmt.Sprintf("logs:\n%s", lines)
155+
fmt.Sprintf("gasConsumed: %d", receipt.GasConsumed)
156+
if len(receipt.ContractAddress) != 0 {
157+
output += fmt.Sprintf("\ncontractAddress: %s %s", receipt.ContractAddress,
158+
match(receipt.ContractAddress, "address"))
159+
}
160+
if len(logs) != 0 {
161+
output += fmt.Sprintf("\nlogs:\n%s", logs)
162+
}
163+
return output
169164
}
170165

171166
func match(in string, matchType string) string {

0 commit comments

Comments
 (0)