-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtransaction-wrapper.go
117 lines (110 loc) · 3.64 KB
/
transaction-wrapper.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package txstatus
import (
"encoding/json"
"fmt"
"github.com/gagliardetto/solana-go"
)
type Transaction struct {
Message Message `json:"message"`
Signatures []solana.Signature `json:"signatures"`
}
type Message struct {
AccountKeys []AccountKey `json:"accountKeys"`
Instructions []json.RawMessage `json:"instructions"`
RecentBlockhash string `json:"recentBlockhash"`
}
type AccountKey struct {
Pubkey string `json:"pubkey"`
Signer bool `json:"signer"`
Source string `json:"source"`
Writable bool `json:"writable"`
}
func FromTransaction(solTx solana.Transaction) (Transaction, error) {
tx := Transaction{
Message: Message{
AccountKeys: make([]AccountKey, len(solTx.Message.AccountKeys)),
Instructions: make([]json.RawMessage, len(solTx.Message.Instructions)),
},
Signatures: solTx.Signatures,
}
for i, accKey := range solTx.Message.AccountKeys {
isWr, err := solTx.IsWritable(accKey)
if err != nil {
return tx, fmt.Errorf("failed to check if account key #%d is writable: %w", i, err)
}
tx.Message.AccountKeys[i] = AccountKey{
Pubkey: accKey.String(),
Signer: solTx.IsSigner(accKey),
Source: "transaction", // TODO: what is this?
Writable: isWr,
}
}
for i, inst := range solTx.Message.Instructions {
tx.Message.Instructions[i] = json.RawMessage(inst.Data)
}
tx.Message.RecentBlockhash = solTx.Message.RecentBlockhash.String()
return tx, nil
}
// {
// "message": {
// "accountKeys": [
// {
// "pubkey": "GdnSyH3YtwcxFvQrVVJMm1JhTS4QVX7MFsX56uJLUfiZ",
// "signer": true,
// "source": "transaction",
// "writable": true
// },
// {
// "pubkey": "sCtiJieP8B3SwYnXemiLpRFRR8KJLMtsMVN25fAFWjW",
// "signer": false,
// "source": "transaction",
// "writable": true
// },
// {
// "pubkey": "SysvarS1otHashes111111111111111111111111111",
// "signer": false,
// "source": "transaction",
// "writable": false
// },
// {
// "pubkey": "SysvarC1ock11111111111111111111111111111111",
// "signer": false,
// "source": "transaction",
// "writable": false
// },
// {
// "pubkey": "Vote111111111111111111111111111111111111111",
// "signer": false,
// "source": "transaction",
// "writable": false
// }
// ],
// "instructions": [
// {
// "parsed": {
// "info": {
// "clockSysvar": "SysvarC1ock11111111111111111111111111111111",
// "slotHashesSysvar": "SysvarS1otHashes111111111111111111111111111",
// "vote": {
// "hash": "EYEnTi2GEy7ApyWm63hvpi6c69Kvfcsc3TtdFu92yLxr",
// "slots": [
// 431996
// ],
// "timestamp": null
// },
// "voteAccount": "sCtiJieP8B3SwYnXemiLpRFRR8KJLMtsMVN25fAFWjW",
// "voteAuthority": "GdnSyH3YtwcxFvQrVVJMm1JhTS4QVX7MFsX56uJLUfiZ"
// },
// "type": "vote"
// },
// "program": "vote",
// "programId": "Vote111111111111111111111111111111111111111",
// "stackHeight": null
// }
// ],
// "recentBlockhash": "G9jx9FCto47ebxHgXBomE14hvG1WiwGD8LL3p7pEt1JX"
// },
// "signatures": [
// "55y2u7sCd8mZ5LqtdrWnqJ6WBxVojXGXBd5KVuJFZrMJiC6bzziMdaPB3heNWqK9JpB5KfXSY4wTzf1AbyNSwUPd"
// ]
// }