Skip to content

Commit

Permalink
Merge pull request #350 from aergoio/release/2.5.2-dev1
Browse files Browse the repository at this point in the history
Release v2.5.2
  • Loading branch information
hayarobi committed Feb 20, 2024
2 parents 877e52d + cc53115 commit 03f10fe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 101 deletions.
6 changes: 2 additions & 4 deletions cmd/aergocli/cmd/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ func execListEvent(cmd *cobra.Command, args []string) {
return
}
for _, event := range events.GetEvents() {
res := jsonrpc.ConvEvent(event)
cmd.Println(jsonrpc.MarshalJSON(res))
cmd.Println(jsonrpc.MarshalJSON(event))
}
}

Expand All @@ -109,7 +108,6 @@ func execStreamEvent(cmd *cobra.Command, args []string) {
cmd.Printf("Failed: %s\n", err.Error())
return
}
res := jsonrpc.ConvEvent(event)
cmd.Println(jsonrpc.MarshalJSON(res))
cmd.Println(jsonrpc.MarshalJSON(event))
}
}
3 changes: 1 addition & 2 deletions cmd/aergocli/cmd/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
res := jsonrpc.ConvReceipt(msg)
cmd.Println(jsonrpc.MarshalJSON(res))
cmd.Println(jsonrpc.MarshalJSON(msg))
},
},
)
Expand Down
23 changes: 21 additions & 2 deletions cmd/aergocli/cmd/signtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
func init() {
rootCmd.AddCommand(signCmd)
signCmd.Flags().StringVar(&jsonTx, "jsontx", "", "transaction json to sign")
signCmd.Flags().StringVar(&jsonPath, "jsontxpath", "", "transaction json file path to sign")
signCmd.Flags().StringVar(&address, "address", "1", "address of account to use for signing")
signCmd.Flags().StringVar(&pw, "password", "", "local account password")
signCmd.Flags().StringVar(&privKey, "key", "", "base58 encoded key for sign")
rootCmd.AddCommand(verifyCmd)
verifyCmd.Flags().StringVar(&jsonTx, "jsontx", "", "transaction list json to verify")
verifyCmd.Flags().StringVar(&jsonPath, "jsontxpath", "", "transaction json file path to verify")
verifyCmd.Flags().BoolVar(&remote, "remote", false, "verify in the node")
}

Expand All @@ -32,10 +34,18 @@ var signCmd = &cobra.Command{
PreRun: preConnectAergo,
Run: func(cmd *cobra.Command, args []string) {
var err error
if jsonTx == "" {
if jsonTx == "" && jsonPath == "" {
cmd.Printf("need to transaction json input")
return
}
if jsonTx == "" {
b, readerr := os.ReadFile(jsonPath)
if readerr != nil {
cmd.Printf("Failed to read --jsontxpath\n" + readerr.Error())
return
}
jsonTx = string(b)
}
param, err := jsonrpc.ParseBase58TxBody([]byte(jsonTx))
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
Expand Down Expand Up @@ -102,10 +112,19 @@ var verifyCmd = &cobra.Command{
Short: "Verify transaction",
PreRun: preConnectAergo,
Run: func(cmd *cobra.Command, args []string) {
if jsonTx == "" {
if jsonTx == "" && jsonPath == "" {
cmd.Printf("need to transaction json input")
return
}
if jsonTx == "" {
b, readerr := os.ReadFile(jsonPath)
if readerr != nil {
cmd.Printf("Failed to read --jsontxpath\n" + readerr.Error())
return
}
jsonTx = string(b)
}

param, err := jsonrpc.ParseBase58Tx([]byte(jsonTx))
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
Expand Down
3 changes: 1 addition & 2 deletions rpc/web3/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,7 @@ func (api *Web3APIv1) GetReceipt() (handler http.Handler, ok bool) {
return commonResponseHandler(&types.Empty{}, err), true
}

output := jsonrpc.ConvReceipt(result)
return stringResponseHandler(jsonrpc.MarshalJSON(output), nil), true
return stringResponseHandler(jsonrpc.MarshalJSON(result), nil), true
}

func (api *Web3APIv1) GetReceipts() (handler http.Handler, ok bool) {
Expand Down
104 changes: 14 additions & 90 deletions types/jsonrpc/receipt.go
Original file line number Diff line number Diff line change
@@ -1,85 +1,9 @@
package jsonrpc

import (
"math/big"

"github.com/aergoio/aergo/v2/internal/enc/base58"
"github.com/aergoio/aergo/v2/types"
)

func ConvReceipt(msg *types.Receipt) *InOutReceipt {
if msg == nil {
return nil
}
r := &InOutReceipt{}
r.ContractAddress = types.EncodeAddress(msg.ContractAddress)
r.Status = msg.Status
r.Ret = msg.Ret
r.TxHash = base58.Encode(msg.TxHash)
r.FeeUsed = new(big.Int).SetBytes(msg.FeeUsed).String()
r.CumulativeFeeUsed = new(big.Int).SetBytes(msg.CumulativeFeeUsed).String()
r.Bloom = msg.Bloom
if msg.Events != nil {
r.Events = make([]*InOutEvent, len(msg.Events))
for i, e := range msg.Events {
r.Events[i] = ConvEvent(e)
}
}
r.BlockHash = base58.Encode(msg.BlockHash)
r.BlockNo = msg.BlockNo
r.TxIndex = msg.TxIndex
r.From = types.EncodeAddress(msg.From)
r.To = types.EncodeAddress(msg.To)
r.FeeDelegation = msg.FeeDelegation
r.GasUsed = msg.GasUsed
return r
}

type InOutReceipt struct {
ContractAddress string `json:"contractAddress"`
Status string `json:"status"`
Ret string `json:"ret"`
TxHash string `json:"txHash"`
FeeUsed string `json:"feeUsed"`
CumulativeFeeUsed string `json:"cumulativeFeeUsed,omitempty"`
Bloom []byte `json:"bloom,omitempty"`
Events []*InOutEvent `json:"events,omitempty"`
BlockHash string `json:"blockHash,omitempty"`
BlockNo uint64 `json:"blockNo,omitempty"`
TxIndex int32 `json:"txIndex,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
FeeDelegation bool `json:"feeDelegation,omitempty"`
GasUsed uint64 `json:"gasUsed,omitempty"`
}

func ConvEvent(msg *types.Event) *InOutEvent {
if msg == nil {
return nil
}
return &InOutEvent{
ContractAddress: types.EncodeAddress(msg.ContractAddress),
EventName: msg.EventName,
JsonArgs: msg.JsonArgs,
EventIdx: msg.EventIdx,
TxHash: base58.Encode(msg.TxHash),
BlockHash: base58.Encode(msg.BlockHash),
BlockNo: msg.BlockNo,
TxIndex: msg.TxIndex,
}
}

type InOutEvent struct {
ContractAddress string `json:"contractAddress"`
EventName string `json:"eventName"`
JsonArgs string `json:"jsonArgs"`
EventIdx int32 `json:"eventIdx"`
TxHash string `json:"txHash"`
BlockHash string `json:"blockHash"`
BlockNo uint64 `json:"blockNo"`
TxIndex int32 `json:"txIndex"`
}

func ConvAbi(msg *types.ABI) *InOutAbi {
if msg == nil {
return nil
Expand Down Expand Up @@ -166,16 +90,16 @@ func ConvReceipts(msg *types.Receipts) *InOutReceipts {

rs := &InOutReceipts{}
rs.BlockNo = msg.GetBlockNo()
rs.Receipts = make([]*InOutReceipt, len(msg.Get()))
rs.Receipts = make([]*types.Receipt, len(msg.Get()))
for i, receipt := range msg.Get() {
rs.Receipts[i] = ConvReceipt(receipt)
rs.Receipts[i] = receipt
}
return rs
}

type InOutReceipts struct {
Receipts []*InOutReceipt `json:"receipts"`
BlockNo uint64 `json:"blockNo,omitempty"`
Receipts []*types.Receipt `json:"receipts"`
BlockNo uint64 `json:"blockNo,omitempty"`
}

func ConvReceiptsPaged(msg *types.ReceiptsPaged) *InOutReceiptsPaged {
Expand All @@ -188,20 +112,20 @@ func ConvReceiptsPaged(msg *types.ReceiptsPaged) *InOutReceiptsPaged {
rp.Offset = msg.GetOffset()
rp.Size = msg.GetSize()
rp.BlockNo = msg.GetBlockNo()
rp.Receipts = make([]*InOutReceipt, len(msg.Get()))
rp.Receipts = make([]*types.Receipt, len(msg.Get()))
for i, receipt := range msg.Get() {
rp.Receipts[i] = ConvReceipt(receipt)
rp.Receipts[i] = receipt
}

return rp
}

type InOutReceiptsPaged struct {
Total uint32 `json:"total,omitempty"`
Offset uint32 `json:"offset,omitempty"`
Size uint32 `json:"size,omitempty"`
Receipts []*InOutReceipt `json:"receipts"`
BlockNo uint64 `json:"blockNo,omitempty"`
Total uint32 `json:"total,omitempty"`
Offset uint32 `json:"offset,omitempty"`
Size uint32 `json:"size,omitempty"`
Receipts []*types.Receipt `json:"receipts"`
BlockNo uint64 `json:"blockNo,omitempty"`
}

func ConvEvents(msg *types.EventList) *InOutEventList {
Expand All @@ -210,13 +134,13 @@ func ConvEvents(msg *types.EventList) *InOutEventList {
}

rs := &InOutEventList{}
rs.Events = make([]*InOutEvent, len(msg.Events))
rs.Events = make([]*types.Event, len(msg.Events))
for i, event := range msg.Events {
rs.Events[i] = ConvEvent(event)
rs.Events[i] = event
}
return rs
}

type InOutEventList struct {
Events []*InOutEvent `json:"events,omitempty"`
Events []*types.Event `json:"events,omitempty"`
}
2 changes: 1 addition & 1 deletion types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (r *Receipt) MarshalJSON() ([]byte, error) {
b.WriteString(`","status":"`)
b.WriteString(r.Status)
if len(r.Ret) == 0 {
b.WriteString(`","ret": {}`)
b.WriteString(`","ret": ""`)
} else if r.Status == "ERROR" {
js, _ := json.Marshal(r.Ret)
b.WriteString(`","ret": `)
Expand Down

0 comments on commit 03f10fe

Please sign in to comment.