@@ -8,7 +8,6 @@ package action
8
8
9
9
import (
10
10
"context"
11
- "errors"
12
11
"fmt"
13
12
"strconv"
14
13
@@ -100,72 +99,68 @@ func printActionProto(action *iotextypes.Action) (string, error) {
100
99
log .L ().Error ("failed to convert bytes into address" , zap .Error (err ))
101
100
return "" , err
102
101
}
102
+ output := fmt .Sprintf ("\n version: %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" ))
103
108
switch {
104
109
case action .Core .GetTransfer () != nil :
105
110
transfer := action .Core .GetTransfer ()
106
- return fmt .Sprintf ("\n version: %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 " +
113
112
fmt .Sprintf (" recipient: %s %s\n " , transfer .Recipient ,
114
113
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 "
120
119
case action .Core .GetExecution () != nil :
121
120
execution := action .Core .GetExecution ()
122
- return fmt .Sprintf ("\n version: %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 " +
129
122
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 ("\n version: %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
148
135
}
149
136
150
137
func printReceiptProto (receipt * iotextypes.Receipt ) string {
151
- lines := make ([]string , 0 )
138
+ logs := make ([]string , 0 )
152
139
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 " ,
154
141
l .Index , l .BlockNumber , l .TxnHash , l .Address , l .Data )
155
142
for _ , t := range l .Topics {
156
- line += fmt .Sprintf (" %s\n " , t )
143
+ log += fmt .Sprintf (" %s\n " , t )
157
144
}
158
- lines = append (lines , line )
145
+ logs = append (logs , log )
159
146
}
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" )) +
163
153
fmt .Sprintf ("actHash: %x\n " , receipt .ActHash ) +
164
154
// 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 ("\n contractAddress: %s %s" , receipt .ContractAddress ,
158
+ match (receipt .ContractAddress , "address" ))
159
+ }
160
+ if len (logs ) != 0 {
161
+ output += fmt .Sprintf ("\n logs:\n %s" , logs )
162
+ }
163
+ return output
169
164
}
170
165
171
166
func match (in string , matchType string ) string {
0 commit comments