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/gas obj #30

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix obj in IWriteTransactionAPI models
  • Loading branch information
pavel.chernyshev committed Aug 13, 2024
commit 11f5186c266f276b89463d518a81b33ec0abcbf6
41 changes: 31 additions & 10 deletions examples/transaction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"

"github.com/block-vision/sui-go-sdk/constant"
"github.com/block-vision/sui-go-sdk/models"
"github.com/block-vision/sui-go-sdk/signer"
Expand Down Expand Up @@ -214,6 +215,8 @@ func SuiXQueryTransactionBlocks() {
}

func MoveCall() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.MoveCall(ctx, models.MoveCallRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
PackageObjectId: "0x7d584c9a27ca4a546e8203b005b0e9ae746c9bec6c8c3c0bc84611bcf4ceab5f",
Expand All @@ -227,7 +230,7 @@ func MoveCall() {
"web3",
"0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
},
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
})

Expand All @@ -240,11 +243,13 @@ func MoveCall() {
}

func MergeCoins() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.MergeCoins(ctx, models.MergeCoinsRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
PrimaryCoin: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
CoinToMerge: "0x92f03fdec6e0278dcb6fa3f4467eeee3e0bee1ac41825351ef53431677d2e2f7",
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000000",
})

Expand All @@ -257,11 +262,13 @@ func MergeCoins() {
}

func SplitCoin() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.SplitCoin(ctx, models.SplitCoinRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
CoinObjectId: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
SplitAmounts: []string{"1000", "1000"},
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
})

Expand All @@ -274,11 +281,13 @@ func SplitCoin() {
}

func SplitCoinEqual() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.SplitCoinEqual(ctx, models.SplitCoinEqualRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
CoinObjectId: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
SplitCount: "2",
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
})

Expand All @@ -291,13 +300,15 @@ func SplitCoinEqual() {
}

func Publish() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.Publish(ctx, models.PublishRequest{
Sender: "0x4ae8be62692d1bbf892b657ee78a59954240ee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BwICAQQADgYLABMADAELARENAgMAAAABDgoAEQgSAgoALhEJOAgLABEIBugDAAAAAAAAOAkSATgKAgEBAQIA",
},
Dependencies: []string{"0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"},
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
})

Expand All @@ -310,10 +321,12 @@ func Publish() {
}

func TransferObject() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.TransferObject(ctx, models.TransferObjectRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
ObjectId: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
Recipient: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
})
Expand Down Expand Up @@ -344,12 +357,14 @@ func TransferSui() {
}

func Pay() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.Pay(ctx, models.PayRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
SuiObjectId: []string{"0x92f03fdec6e0278dcb6fa3f4467eeee3e0bee1ac41825351ef53431677d2e2f7"},
Recipient: []string{"0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff"},
Amount: []string{"1"},
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000000",
})

Expand Down Expand Up @@ -395,12 +410,14 @@ func PayAllSui() {
}

func RequestAddStake() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.RequestAddStake(ctx, models.AddStakeRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
Coins: []string{"0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"},
Amount: "1",
Validator: "0x884515e99dab69c4c28662149db81ca563ed4c36e0c8ce44a58e40e25a0a64a1",
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
})

Expand All @@ -413,10 +430,12 @@ func RequestAddStake() {
}

func RequestWithdrawStake() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.RequestWithdrawStake(ctx, models.WithdrawStakeRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
StakedObjectId: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
})

Expand All @@ -429,6 +448,8 @@ func RequestWithdrawStake() {
}

func BatchTransaction() {
gasObj := "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1"

rsp, err := cli.BatchTransaction(ctx, models.BatchTransactionRequest{
Signer: "0x4ae8be62692d1bbf892b657ee78a59954240ee0525f20a5b5687a70995cf0eff",
RPCTransactionRequestParams: []models.RPCTransactionRequestParams{
Expand All @@ -454,7 +475,7 @@ func BatchTransaction() {
},
},
},
Gas: "0xc699c6014da947778fe5f740b2e9caf905ca31fb4c81e346f467ae126e3c03f1",
Gas: &gasObj,
GasBudget: "1000",
SuiTransactionBlockBuilderMode: "DevInspect",
})
Expand Down
19 changes: 10 additions & 9 deletions models/write_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"crypto/ed25519"

"github.com/block-vision/sui-go-sdk/models/sui_types"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ type MergeCoinsRequest struct {
PrimaryCoin string `json:"primaryCoin"`
CoinToMerge string `json:"coinToMerge"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand All @@ -56,7 +57,7 @@ type SplitCoinRequest struct {
CoinObjectId string `json:"coinObjectId"`
SplitAmounts []string `json:"splitAmounts"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand All @@ -67,7 +68,7 @@ type SplitCoinEqualRequest struct {
CoinObjectId string `json:"coinObjectId"`
SplitCount string `json:"splitCount"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand All @@ -78,7 +79,7 @@ type PublishRequest struct {
CompiledModules []string `json:"compiled_modules"`
Dependencies []string `json:"dependencies"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand All @@ -88,7 +89,7 @@ type TransferObjectRequest struct {
Signer string `json:"signer"`
ObjectId string `json:"objectId"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
Recipient string `json:"recipient"`
Expand All @@ -111,7 +112,7 @@ type PayRequest struct {
Recipient []string `json:"recipient"`
Amount []string `json:"amount"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand Down Expand Up @@ -145,7 +146,7 @@ type AddStakeRequest struct {
// the validator's Sui address
Validator string `json:"validator"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand All @@ -156,7 +157,7 @@ type WithdrawStakeRequest struct {
// StakedSui object ID
StakedObjectId string `json:"stakedObjectId"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
}
Expand All @@ -173,7 +174,7 @@ type BatchTransactionRequest struct {
// list of transaction request parameters
RPCTransactionRequestParams []RPCTransactionRequestParams `json:"RPCTransactionRequestParams"`
// gas object to be used in this transaction, node will pick one from the signer's possession if not provided
Gas string `json:"gas"`
Gas *string `json:"gas"`
// the gas budget, the transaction will fail if the gas cost exceed the budget
GasBudget string `json:"gasBudget"`
// Whether this is a regular transaction or a Dev Inspect Transaction
Expand Down
2 changes: 2 additions & 0 deletions sui/write_transaction_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"context"
"encoding/json"
"errors"

"github.com/block-vision/sui-go-sdk/common/httpconn"
"github.com/block-vision/sui-go-sdk/models"
"github.com/tidwall/gjson"
)

// TODO fix Gas
type IWriteTransactionAPI interface {
SuiExecuteTransactionBlock(ctx context.Context, req models.SuiExecuteTransactionBlockRequest) (models.SuiTransactionBlockResponse, error)
MoveCall(ctx context.Context, req models.MoveCallRequest) (models.TxnMetaData, error)
Expand Down