-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaddress.go
99 lines (83 loc) · 2.08 KB
/
address.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
package splitter_token
import (
"crypto/ed25519"
"encoding/binary"
"github.com/code-payments/code-server/pkg/solana"
)
var (
poolStatePrefix = []byte("pool_state")
poolVaultPrefix = []byte("pool_vault")
commitmentStatePrefix = []byte("commitment_state")
commitmentVaultPrefix = []byte("commitment_vault")
proofPrefix = []byte("proof")
)
type GetPoolStateAddressArgs struct {
Mint ed25519.PublicKey
Authority ed25519.PublicKey
Name string
}
type GetPoolVaultAddressArgs struct {
Pool ed25519.PublicKey
}
func GetPoolStateAddress(args *GetPoolStateAddressArgs) (ed25519.PublicKey, uint8, error) {
return solana.FindProgramAddressAndBump(
PROGRAM_ID,
poolStatePrefix,
args.Mint,
args.Authority,
[]byte(args.Name),
)
}
func GetPoolVaultAddress(args *GetPoolVaultAddressArgs) (ed25519.PublicKey, uint8, error) {
return solana.FindProgramAddressAndBump(
PROGRAM_ID,
poolVaultPrefix,
args.Pool,
)
}
type GetCommitmentStateAddressArgs struct {
Pool ed25519.PublicKey
RecentRoot Hash
Transcript Hash
Destination ed25519.PublicKey
Amount uint64
}
type GetCommitmentVaultAddressArgs struct {
Pool ed25519.PublicKey
Commitment ed25519.PublicKey
}
func GetCommitmentStateAddress(args *GetCommitmentStateAddressArgs) (ed25519.PublicKey, uint8, error) {
amountBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(amountBytes, args.Amount)
return solana.FindProgramAddressAndBump(
PROGRAM_ID,
commitmentStatePrefix,
args.Pool,
args.RecentRoot,
args.Transcript,
args.Destination,
amountBytes,
)
}
func GetCommitmentVaultAddress(args *GetCommitmentVaultAddressArgs) (ed25519.PublicKey, uint8, error) {
return solana.FindProgramAddressAndBump(
PROGRAM_ID,
commitmentVaultPrefix,
args.Pool,
args.Commitment,
)
}
type GetProofAddressArgs struct {
Pool ed25519.PublicKey
MerkleRoot Hash
Commitment ed25519.PublicKey
}
func GetProofAddress(args *GetProofAddressArgs) (ed25519.PublicKey, uint8, error) {
return solana.FindProgramAddressAndBump(
PROGRAM_ID,
proofPrefix,
args.Pool,
args.MerkleRoot,
args.Commitment,
)
}