Skip to content

Commit

Permalink
update compute unit& price
Browse files Browse the repository at this point in the history
  • Loading branch information
ciel committed Jun 1, 2024
1 parent a2b185b commit 504a14a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 38 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
40 changes: 24 additions & 16 deletions types/compute-budget/SetComputeUnitLimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -40,54 +40,62 @@ 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),
}}
}

// 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 {
return 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)
Expand Down
34 changes: 21 additions & 13 deletions types/compute-budget/SetComputeUnitPrice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -38,32 +38,32 @@ 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),
}}
}

// 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")
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 504a14a

Please sign in to comment.