-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprogram.go
65 lines (51 loc) · 1.53 KB
/
program.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package compute_budget
import (
"crypto/ed25519"
"encoding/binary"
"errors"
"github.com/code-payments/code-server/pkg/solana"
)
// ComputeBudget111111111111111111111111111111
var ProgramKey = ed25519.PublicKey{3, 6, 70, 111, 229, 33, 23, 50, 255, 236, 173, 186, 114, 195, 155, 231, 188, 140, 229, 187, 197, 247, 18, 107, 44, 67, 155, 58, 64, 0, 0, 0}
const (
commandRequestUnits uint8 = iota
commandRequestHeapFrame
commandSetComputeUnitLimit
commandSetComputeUnitPrice
)
func SetComputeUnitLimit(computeUnitLimit uint32) solana.Instruction {
data := make([]byte, 1+4)
data[0] = commandSetComputeUnitLimit
binary.LittleEndian.PutUint32(data[1:], computeUnitLimit)
return solana.NewInstruction(
ProgramKey[:],
data,
)
}
func SetComputeUnitPrice(computeUnitPrice uint64) solana.Instruction {
data := make([]byte, 1+8)
data[0] = commandSetComputeUnitPrice
binary.LittleEndian.PutUint64(data[1:], computeUnitPrice)
return solana.NewInstruction(
ProgramKey[:],
data,
)
}
func DecompileSetComputeUnitLimitIxnData(data []byte) (uint32, error) {
if len(data) != 5 {
return 0, errors.New("invalid length")
}
if data[0] != commandSetComputeUnitLimit {
return 0, errors.New("invalid instruction")
}
return binary.LittleEndian.Uint32(data[1:]), nil
}
func DecompileSetComputeUnitPriceIxnData(data []byte) (uint64, error) {
if len(data) != 9 {
return 0, errors.New("invalid length")
}
if data[0] != commandSetComputeUnitPrice {
return 0, errors.New("invalid instruction")
}
return binary.LittleEndian.Uint64(data[1:]), nil
}