From 504a14a05a71f53f468f9620a0107fcb34b26e24 Mon Sep 17 00:00:00 2001 From: ciel Date: Sun, 2 Jun 2024 02:30:04 +0800 Subject: [PATCH] update compute unit& price --- go.mod | 3 -- go.sum | 6 ---- types/compute-budget/SetComputeUnitLimit.go | 40 ++++++++++++--------- types/compute-budget/SetComputeUnitPrice.go | 34 +++++++++++------- 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/go.mod b/go.mod index 812bc17..8947bdc 100644 --- a/go.mod +++ b/go.mod @@ -4,16 +4,13 @@ module github.com/cielu/go-solana go 1.18 require ( - filippo.io/edwards25519 v1.1.0 github.com/deckarep/golang-set/v2 v2.6.0 github.com/gorilla/websocket v1.5.1 github.com/mr-tron/base58 v1.2.0 - github.com/near/borsh-go v0.3.1 github.com/tyler-smith/go-bip39 v1.1.0 ) require ( - github.com/mitchellh/mapstructure v1.5.0 // indirect golang.org/x/crypto v0.22.0 // indirect golang.org/x/net v0.24.0 // indirect ) diff --git a/go.sum b/go.sum index e844b18..1a7ad2c 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,9 @@ -filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= -filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM= github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/near/borsh-go v0.3.1 h1:ukNbhJlPKxfua0/nIuMZhggSU8zvtRP/VyC25LLqPUA= -github.com/near/borsh-go v0.3.1/go.mod h1:NeMochZp7jN/pYFuxLkrZtmLqbADmnp/y1+/dL+AsyQ= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/types/compute-budget/SetComputeUnitLimit.go b/types/compute-budget/SetComputeUnitLimit.go index 3c3f8c8..909dfc2 100644 --- a/types/compute-budget/SetComputeUnitLimit.go +++ b/types/compute-budget/SetComputeUnitLimit.go @@ -26,11 +26,11 @@ type SetComputeUnitLimit struct { Units uint32 } -func (inst *SetComputeUnitLimit) SetAccounts([]*base.AccountMeta) error { +func (obj *SetComputeUnitLimit) SetAccounts(accounts []*base.AccountMeta) error { return nil } -func (inst SetComputeUnitLimit) GetAccounts() (accounts []base.AccountMeta) { +func (obj SetComputeUnitLimit) GetAccounts() (accounts []*base.AccountMeta) { return } @@ -40,15 +40,15 @@ func NewSetComputeUnitLimitInstructionBuilder() *SetComputeUnitLimit { return nd } -// Unit limit -func (inst *SetComputeUnitLimit) SetUnits(units uint32) *SetComputeUnitLimit { - inst.Units = units - return inst +// SetUnits limit +func (obj *SetComputeUnitLimit) SetUnits(units uint32) *SetComputeUnitLimit { + obj.Units = units + return obj } -func (inst SetComputeUnitLimit) Build() *Instruction { +func (obj SetComputeUnitLimit) Build() *Instruction { return &Instruction{BaseVariant: encodbin.BaseVariant{ - Impl: inst, + Impl: obj, TypeID: encodbin.TypeIDFromUint8(Instruction_SetComputeUnitLimit), }} } @@ -56,27 +56,27 @@ func (inst SetComputeUnitLimit) Build() *Instruction { // ValidateAndBuild validates the instruction parameters and accounts; // if there is a validation error, it returns the error. // Otherwise, it builds and returns the instruction. -func (inst SetComputeUnitLimit) ValidateAndBuild() (*Instruction, error) { - if err := inst.Validate(); err != nil { +func (obj SetComputeUnitLimit) ValidateAndBuild() (*Instruction, error) { + if err := obj.Validate(); err != nil { return nil, err } - return inst.Build(), nil + return obj.Build(), nil } -func (inst *SetComputeUnitLimit) Validate() error { +func (obj *SetComputeUnitLimit) Validate() error { // Check whether all (required) parameters are set: { - if inst.Units == 0 { + if obj.Units == 0 { return errors.New("Units parameter is not set") } - if inst.Units > MAX_COMPUTE_UNIT_LIMIT { + if obj.Units > MAX_COMPUTE_UNIT_LIMIT { return errors.New("Units parameter exceeds the maximum compute unit") } } return nil } -func (obj SetComputeUnitLimit) MarshalWithEncoder(encoder encodbin.Encoder) (err error) { +func (obj SetComputeUnitLimit) MarshalWithEncoder(encoder *encodbin.Encoder) (err error) { // Serialize `Units` param: err = encoder.Encode(obj.Units) if err != nil { @@ -84,10 +84,18 @@ func (obj SetComputeUnitLimit) MarshalWithEncoder(encoder encodbin.Encoder) (err } return nil } +func (obj *SetComputeUnitLimit) UnmarshalWithDecoder(decoder *encodbin.Decoder) (err error) { + // Deserialize `Units`: + err = decoder.Decode(&obj.Units) + if err != nil { + return err + } + return nil +} // NewSetComputeUnitLimitInstruction declares a new SetComputeUnitLimit instruction with the provided parameters and accounts. func NewSetComputeUnitLimitInstruction( - // Parameters: +// Parameters: units uint32, ) *SetComputeUnitLimit { return NewSetComputeUnitLimitInstructionBuilder().SetUnits(units) diff --git a/types/compute-budget/SetComputeUnitPrice.go b/types/compute-budget/SetComputeUnitPrice.go index eb340f0..f6dbd73 100644 --- a/types/compute-budget/SetComputeUnitPrice.go +++ b/types/compute-budget/SetComputeUnitPrice.go @@ -24,11 +24,11 @@ type SetComputeUnitPrice struct { MicroLamports uint64 } -func (obj *SetComputeUnitPrice) SetAccounts([]*base.AccountMeta) error { +func (obj *SetComputeUnitPrice) SetAccounts(accounts []*base.AccountMeta) error { return nil } -func (slice SetComputeUnitPrice) GetAccounts() (accounts []*base.AccountMeta) { +func (obj SetComputeUnitPrice) GetAccounts() (accounts []*base.AccountMeta) { return } @@ -38,14 +38,14 @@ func NewSetComputeUnitPriceInstructionBuilder() *SetComputeUnitPrice { return nd } -func (inst *SetComputeUnitPrice) SetMicroLamports(microLamports uint64) *SetComputeUnitPrice { - inst.MicroLamports = microLamports - return inst +func (obj *SetComputeUnitPrice) SetMicroLamports(microLamports uint64) *SetComputeUnitPrice { + obj.MicroLamports = microLamports + return obj } -func (inst SetComputeUnitPrice) Build() *Instruction { +func (obj SetComputeUnitPrice) Build() *Instruction { return &Instruction{BaseVariant: encodbin.BaseVariant{ - Impl: inst, + Impl: obj, TypeID: encodbin.TypeIDFromUint8(Instruction_SetComputeUnitPrice), }} } @@ -53,17 +53,17 @@ func (inst SetComputeUnitPrice) Build() *Instruction { // ValidateAndBuild validates the instruction parameters and accounts; // if there is a validation error, it returns the error. // Otherwise, it builds and returns the instruction. -func (inst SetComputeUnitPrice) ValidateAndBuild() (*Instruction, error) { - if err := inst.Validate(); err != nil { +func (obj SetComputeUnitPrice) ValidateAndBuild() (*Instruction, error) { + if err := obj.Validate(); err != nil { return nil, err } - return inst.Build(), nil + return obj.Build(), nil } -func (inst *SetComputeUnitPrice) Validate() error { +func (obj *SetComputeUnitPrice) Validate() error { // Check whether all (required) parameters are set: { - if inst.MicroLamports == 0 { + if obj.MicroLamports == 0 { return errors.New("MicroLamports parameter is not set") } } @@ -78,10 +78,18 @@ func (obj SetComputeUnitPrice) MarshalWithEncoder(encoder *encodbin.Encoder) (er } return nil } +func (obj *SetComputeUnitPrice) UnmarshalWithDecoder(decoder *encodbin.Decoder) (err error) { + // Deserialize `MicroLamports`: + err = decoder.Decode(&obj.MicroLamports) + if err != nil { + return err + } + return nil +} // NewSetComputeUnitPriceInstruction declares a new SetComputeUnitPrice instruction with the provided parameters and accounts. func NewSetComputeUnitPriceInstruction( - // Parameters: +// Parameters: microLamports uint64, ) *SetComputeUnitPrice { return NewSetComputeUnitPriceInstructionBuilder().SetMicroLamports(microLamports)