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