Skip to content

Commit

Permalink
Merge pull request #38 from pymongo/main
Browse files Browse the repository at this point in the history
Fix: SuiDevInspectTransactionBlock example and parse results in rsp
  • Loading branch information
JaydenLink authored Oct 21, 2024
2 parents c2c872d + f8a8794 commit 3970825
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
15 changes: 12 additions & 3 deletions examples/transaction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"encoding/json"
"fmt"

"github.com/block-vision/sui-go-sdk/constant"
Expand Down Expand Up @@ -34,6 +35,7 @@ func main() {
//BatchTransaction()
//SuiExecuteTransactionBlock()
//SuiDryRunTransactionBlock()
//SuiDevInspectTransactionBlock()
//SignAndExecuteTransactionBlock()
}

Expand Down Expand Up @@ -72,18 +74,25 @@ func SuiDryRunTransactionBlock() {
}

func SuiDevInspectTransactionBlock() {
type moveCallResult struct {
ReturnValues [2]interface{}
}
rsp, err := cli.SuiDevInspectTransactionBlock(ctx, models.SuiDevInspectTransactionBlockRequest{
Sender: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
TxBytes: "AAACAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQEAAAAAAAAAAQEAjgDW4hJZlqvw654RGR3SdndKkdjoC0pzXQLxja/NUahLowQAAAAAACBEQGwClI9RQX68dzbN7PN29/Pw/Sc1hbtZwNAny7wZ+wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMKc3VpX3N5c3RlbRZyZXF1ZXN0X3dpdGhkcmF3X3N0YWtlAAIBAAABAQC3+Y0yfxn2dDR+HkBkFAglMULW5+UJOnyW7ajN/X2btQEqzrI5x8BMQ6LjmCSgAykfjisdYCcyTfW79nyzDB/PvtZBpwAAAAAAIAm+IREDziwoZLm7lc4ZKegZ2J5viEgoss9zgrFkHLh6t/mNMn8Z9nQ0fh5AZBQIJTFC1uflCTp8lu2ozf19m7XoAwAAAAAAAFDhjyoAAAAAAA==",
GasPrice: "1000",
Epoch: "87",
TxBytes: "AAUBAFIMicbHjFZu7Q6/JPhUqMItj90GpvFq0B8Qja1/G6rqFSjPCgAAAAAgU+6E0DJf97dwaRV0MdseKxCPU97monpYtyfJSa7jKQAACKCGAQAAAAAAAAiAlpgAAAAAAAABAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYtKc8KAAAAACBhjSVWnhYSnxbZuJWgDlXi2j3pp7gqJJizx29rU/Ly+QEAy/R0ipZdRp6jo2zwzMV0O5bC0K5t7gdi7T7KZfrAf34EcG9vbBBnZXRfbGV2ZWwyX3JhbmdlAgcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgNzdWkDU1VJAAf3FSwFkwSAzXQNcxG1uLRcb0iOOlOhHD90pvrDalLg1wZEQlVTREMGREJVU0RDAAUBAAABAQABAgABAwABBAA=",
})

if err != nil {
fmt.Println(err.Error())
return
}

var moveCallReturn []moveCallResult
err = json.Unmarshal(rsp.Results, &moveCallReturn)
if err != nil {
fmt.Println("json", err.Error())
return
}
utils.PrettyPrint(rsp)
}

Expand Down
1 change: 1 addition & 0 deletions models/read_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ type SuiTransactionBlockResponse struct {
TimestampMs string `json:"timestampMs,omitempty"`
Checkpoint string `json:"checkpoint,omitempty"`
ConfirmedLocalExecution bool `json:"confirmedLocalExecution,omitempty"`
Results json.RawMessage `json:"results,omitempty"`
}

func (o ObjectChange) GetObjectChangeAddressOwner() string {
Expand Down
24 changes: 15 additions & 9 deletions sui/read_transaction_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,29 @@ func (s *suiReadTransactionFromSuiImpl) SuiDryRunTransactionBlock(ctx context.Co
// Which allows for nearly any transaction (or Move call) with any arguments.
// Detailed results are provided, including both the transaction effects and any return values.
func (s *suiReadTransactionFromSuiImpl) SuiDevInspectTransactionBlock(ctx context.Context, req models.SuiDevInspectTransactionBlockRequest) (models.SuiTransactionBlockResponse, error) {
params := []interface{}{
req.Sender,
req.TxBytes,
}
if req.GasPrice != "" {
params = append(params, req.GasPrice)
}
if req.Epoch != "" {
params = append(params, req.Epoch)
}
var rsp models.SuiTransactionBlockResponse
respBytes, err := s.conn.Request(ctx, httpconn.Operation{
Method: "sui_devInspectTransactionBlock",
Params: []interface{}{
req.Sender,
req.TxBytes,
req.GasPrice,
req.Epoch,
},
Params: params,
})
if err != nil {
return rsp, err
}
if gjson.ParseBytes(respBytes).Get("error").Exists() {
return rsp, errors.New(gjson.ParseBytes(respBytes).Get("error").String())
parsedJson := gjson.ParseBytes(respBytes)
if parsedJson.Get("error").Exists() {
return rsp, errors.New(parsedJson.Get("error").String())
}
err = json.Unmarshal([]byte(gjson.ParseBytes(respBytes).Get("result").Raw), &rsp)
err = json.Unmarshal([]byte(parsedJson.Get("result").Raw), &rsp)
if err != nil {
return rsp, err
}
Expand Down

0 comments on commit 3970825

Please sign in to comment.