Add bcs optional tag to transaction fields
This commit is contained in:
@@ -5,8 +5,8 @@ import "errors"
|
|||||||
var (
|
var (
|
||||||
ErrSignerNotSet = errors.New("signer not set")
|
ErrSignerNotSet = errors.New("signer not set")
|
||||||
ErrSenderNotSet = errors.New("sender not set")
|
ErrSenderNotSet = errors.New("sender not set")
|
||||||
|
ErrSuiClientNotSet = errors.New("sui client not set")
|
||||||
ErrGasDataNotFullySet = errors.New("gas data not fully set")
|
ErrGasDataNotFullySet = errors.New("gas data not fully set")
|
||||||
ErrInvalidSuiAddress = errors.New("invalid sui address")
|
ErrInvalidSuiAddress = errors.New("invalid sui address")
|
||||||
ErrInvalidObjectId = errors.New("invalid object id")
|
ErrInvalidObjectId = errors.New("invalid object id")
|
||||||
ErrSuiClientNotSet = errors.New("sui client not set")
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func NewTransaction() *Transaction {
|
|||||||
data.V1.Kind = &TransactionKind{
|
data.V1.Kind = &TransactionKind{
|
||||||
ProgrammableTransaction: &ProgrammableTransaction{},
|
ProgrammableTransaction: &ProgrammableTransaction{},
|
||||||
}
|
}
|
||||||
|
data.V1.GasData = &GasData{}
|
||||||
|
|
||||||
return &Transaction{
|
return &Transaction{
|
||||||
Data: data,
|
Data: data,
|
||||||
@@ -68,7 +69,7 @@ func (tx *Transaction) SetExpiration(expiration TransactionExpiration) *Transact
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) SetGasPayment(payment []SuiObjectRef) *Transaction {
|
func (tx *Transaction) SetGasPayment(payment []SuiObjectRef) *Transaction {
|
||||||
tx.Data.V1.GasData.Payment = payment
|
tx.Data.V1.GasData.Payment = &payment
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
@@ -111,6 +112,7 @@ func (tx *Transaction) Gas() Argument {
|
|||||||
|
|
||||||
func (tx *Transaction) Add(command Command) Argument {
|
func (tx *Transaction) Add(command Command) Argument {
|
||||||
index := tx.Data.V1.AddCommand(command)
|
index := tx.Data.V1.AddCommand(command)
|
||||||
|
|
||||||
return createTransactionResult(index, nil)
|
return createTransactionResult(index, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +308,9 @@ func (tx *Transaction) Pure(input any) *Argument {
|
|||||||
bcsEncoder := mystenbcs.NewEncoder(&bcsEncodedMsg)
|
bcsEncoder := mystenbcs.NewEncoder(&bcsEncodedMsg)
|
||||||
err := bcsEncoder.Encode(val)
|
err := bcsEncoder.Encode(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Data.V1.AddInput(CallArg{UnresolvedPure: lo.ToPtr(bcsEncodedMsg.Bytes())})
|
tx.Data.V1.AddInput(CallArg{UnresolvedPure: &UnresolvedPure{
|
||||||
|
Value: input,
|
||||||
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
arg := tx.Data.V1.AddInput(CallArg{Pure: &Pure{
|
arg := tx.Data.V1.AddInput(CallArg{Pure: &Pure{
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ func (td *TransactionData) Marshal() ([]byte, error) {
|
|||||||
// TransactionDataV1 https://github.com/MystenLabs/sui/blob/fb27c6c7166f5e4279d5fd1b2ebc5580ca0e81b2/crates/sui-types/src/transaction.rs#L1625
|
// TransactionDataV1 https://github.com/MystenLabs/sui/blob/fb27c6c7166f5e4279d5fd1b2ebc5580ca0e81b2/crates/sui-types/src/transaction.rs#L1625
|
||||||
type TransactionDataV1 struct {
|
type TransactionDataV1 struct {
|
||||||
Kind *TransactionKind
|
Kind *TransactionKind
|
||||||
Sender *models.SuiAddressBytes `bcs:"optional"`
|
Sender *models.SuiAddressBytes
|
||||||
GasData GasData
|
GasData *GasData
|
||||||
Expiration *TransactionExpiration `bcs:"optional"`
|
Expiration *TransactionExpiration `bcs:"optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,17 +81,14 @@ func (td *TransactionDataV1) GetInputObjectIndex(address models.SuiAddress) *uin
|
|||||||
|
|
||||||
// GasData https://github.com/MystenLabs/sui/blob/fb27c6c7166f5e4279d5fd1b2ebc5580ca0e81b2/crates/sui-types/src/transaction.rs#L1600
|
// GasData https://github.com/MystenLabs/sui/blob/fb27c6c7166f5e4279d5fd1b2ebc5580ca0e81b2/crates/sui-types/src/transaction.rs#L1600
|
||||||
type GasData struct {
|
type GasData struct {
|
||||||
Payment []SuiObjectRef
|
Payment *[]SuiObjectRef
|
||||||
Owner *models.SuiAddressBytes
|
Owner *models.SuiAddressBytes
|
||||||
Price *uint64
|
Price *uint64
|
||||||
Budget *uint64
|
Budget *uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gd *GasData) IsFullySet() bool {
|
func (gd *GasData) IsFullySet() bool {
|
||||||
if len(gd.Payment) == 0 {
|
if gd.Payment == nil || gd.Owner == nil || gd.Price == nil || gd.Budget == nil {
|
||||||
return false
|
|
||||||
}
|
|
||||||
if gd.Owner == nil || gd.Price == nil || gd.Budget == nil {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,14 +112,8 @@ type ProgrammableTransaction struct {
|
|||||||
|
|
||||||
// TransactionKind https://github.com/MystenLabs/sui/blob/fb27c6c7166f5e4279d5fd1b2ebc5580ca0e81b2/crates/sui-types/src/transaction.rs#L303
|
// TransactionKind https://github.com/MystenLabs/sui/blob/fb27c6c7166f5e4279d5fd1b2ebc5580ca0e81b2/crates/sui-types/src/transaction.rs#L303
|
||||||
// - ProgrammableTransaction
|
// - ProgrammableTransaction
|
||||||
// - ChangeEpoch
|
|
||||||
// - Genesis
|
|
||||||
// - ConsensusCommitPrologue
|
|
||||||
type TransactionKind struct {
|
type TransactionKind struct {
|
||||||
ProgrammableTransaction *ProgrammableTransaction
|
ProgrammableTransaction *ProgrammableTransaction
|
||||||
ChangeEpoch *bool
|
|
||||||
Genesis *bool
|
|
||||||
ConsensusCommitPrologue *bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*TransactionKind) IsBcsEnum() {}
|
func (*TransactionKind) IsBcsEnum() {}
|
||||||
@@ -146,7 +137,7 @@ func (tk *TransactionKind) Marshal() ([]byte, error) {
|
|||||||
type CallArg struct {
|
type CallArg struct {
|
||||||
Pure *Pure
|
Pure *Pure
|
||||||
Object *ObjectArg
|
Object *ObjectArg
|
||||||
UnresolvedPure any
|
UnresolvedPure *UnresolvedPure
|
||||||
UnresolvedObject *UnresolvedObject
|
UnresolvedObject *UnresolvedObject
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +145,10 @@ type Pure struct {
|
|||||||
Bytes []byte
|
Bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UnresolvedPure struct {
|
||||||
|
Value any
|
||||||
|
}
|
||||||
|
|
||||||
func (*CallArg) IsBcsEnum() {}
|
func (*CallArg) IsBcsEnum() {}
|
||||||
|
|
||||||
type UnresolvedObject struct {
|
type UnresolvedObject struct {
|
||||||
@@ -256,9 +251,9 @@ type NestedResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SuiObjectRef struct {
|
type SuiObjectRef struct {
|
||||||
ObjectId models.SuiAddressBytes
|
ObjectId *models.SuiAddressBytes `bcs:"optional"`
|
||||||
Version uint64
|
Version uint64
|
||||||
Digest models.ObjectDigestBytes
|
Digest *models.ObjectDigestBytes `bcs:"optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SharedObjectRef struct {
|
type SharedObjectRef struct {
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ func generateObjectRef() SuiObjectRef {
|
|||||||
digestBytes, _ := ConvertObjectDigestStringToBytes(models.ObjectDigest(digest))
|
digestBytes, _ := ConvertObjectDigestStringToBytes(models.ObjectDigest(digest))
|
||||||
|
|
||||||
return SuiObjectRef{
|
return SuiObjectRef{
|
||||||
ObjectId: *objectIdBytes,
|
ObjectId: objectIdBytes,
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Digest: *digestBytes,
|
Digest: digestBytes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user