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

Fix: SuiDevInspectTransactionBlock example and parse results in rsp #38

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading