File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,30 @@ func GetCompactWithdrawMessage(args *GetCompactWithdrawMessageArgs) CompactMessa
4949 return hashMessage (message )
5050}
5151
52+ type GetCompactAirdropMessageArgs struct {
53+ Source ed25519.PublicKey
54+ Destinations []ed25519.PublicKey
55+ Amount uint64
56+ NonceAddress ed25519.PublicKey
57+ NonceValue Hash
58+ }
59+
60+ func GetCompactAirdropMessage (args * GetCompactAirdropMessageArgs ) CompactMessage {
61+ amountBytes := make ([]byte , 8 )
62+ binary .LittleEndian .PutUint64 (amountBytes , args .Amount )
63+
64+ var message Message
65+ message = append (message , []byte ("airdrop" )... )
66+ message = append (message , args .Source ... )
67+ message = append (message , args .NonceAddress ... )
68+ message = append (message , args .NonceValue [:]... )
69+ message = append (message , amountBytes ... )
70+ for _ , destination := range args .Destinations {
71+ message = append (message , destination ... )
72+ }
73+ return hashMessage (message )
74+ }
75+
5276func hashMessage (msg Message ) CompactMessage {
5377 h := sha256 .New ()
5478 h .Write (msg )
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ const (
1414 OpcodeExternalRelay Opcode = 20
1515
1616 OpcodeConditionalTransfer Opcode = 12
17+
18+ OpcodeAirdrop Opcode = 30
1719)
1820
1921func putOpcode (dst []byte , v Opcode , offset * int ) {
Original file line number Diff line number Diff line change 1+ package cvm
2+
3+ const (
4+ AirdropVirtrualInstructionDataSize = (SignatureSize + // signature
5+ 8 + // amount
6+ 1 ) // count
7+ )
8+
9+ type AirdropVirtualInstructionArgs struct {
10+ Amount uint64
11+ Count uint8
12+ Signature Signature
13+ }
14+
15+ func NewAirdropVirtualInstruction (
16+ args * AirdropVirtualInstructionArgs ,
17+ ) VirtualInstruction {
18+ var offset int
19+ data := make ([]byte , AirdropVirtrualInstructionDataSize )
20+ putSignature (data , args .Signature , & offset )
21+ putUint64 (data , args .Amount , & offset )
22+ putUint8 (data , args .Count , & offset )
23+
24+ return VirtualInstruction {
25+ Opcode : OpcodeAirdrop ,
26+ Data : data ,
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments