-
Notifications
You must be signed in to change notification settings - Fork 17
/
getSignaturesForAddress.go
90 lines (82 loc) · 2.27 KB
/
getSignaturesForAddress.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"encoding/json"
"fmt"
"github.com/gagliardetto/solana-go"
)
type GetSignaturesForAddressParams struct {
Address solana.PublicKey
Limit int
Before *solana.Signature
Until *solana.Signature
// TODO: add more params
}
func parseGetSignaturesForAddressParams(raw *json.RawMessage) (*GetSignaturesForAddressParams, error) {
var params []any
if err := fasterJson.Unmarshal(*raw, ¶ms); err != nil {
return nil, fmt.Errorf("failed to unmarshal params: %w", err)
}
if len(params) < 1 {
return nil, fmt.Errorf("expected at least 1 param")
}
sigRaw, ok := params[0].(string)
if !ok {
return nil, fmt.Errorf("first argument must be a string")
}
out := &GetSignaturesForAddressParams{}
pk, err := solana.PublicKeyFromBase58(sigRaw)
if err != nil {
return nil, fmt.Errorf("failed to parse pubkey from base58: %w", err)
}
out.Address = pk
if len(params) > 1 {
// the second param should be a map[string]interface{}
// with the optional params
if m, ok := params[1].(map[string]interface{}); ok {
if limit, ok := m["limit"]; ok {
if limit, ok := limit.(float64); ok {
out.Limit = int(limit)
}
}
if before, ok := m["before"]; ok {
if before, ok := before.(string); ok {
sig, err := solana.SignatureFromBase58(before)
if err != nil {
return nil, fmt.Errorf("failed to parse signature from base58: %w", err)
}
out.Before = &sig
}
}
if after, ok := m["until"]; ok {
if after, ok := after.(string); ok {
sig, err := solana.SignatureFromBase58(after)
if err != nil {
return nil, fmt.Errorf("failed to parse signature from base58: %w", err)
}
out.Until = &sig
}
}
}
}
if out.Limit <= 0 || out.Limit > 1000 {
// default limit
out.Limit = 1000
}
return out, nil
}
func getMemoInstructionDataFromTransaction(tx *solana.Transaction) []byte {
for _, instruction := range tx.Message.Instructions {
prog, err := tx.ResolveProgramIDIndex(instruction.ProgramIDIndex)
if err != nil {
continue
}
if prog.IsAnyOf(memoProgramIDV1, memoProgramIDV2) {
return instruction.Data
}
}
return nil
}
var (
memoProgramIDV1 = solana.MPK("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo")
memoProgramIDV2 = solana.MPK("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")
)