-
Notifications
You must be signed in to change notification settings - Fork 212
/
tx.go
56 lines (47 loc) · 1.37 KB
/
tx.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
package vesting
import (
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
"github.com/spacemeshos/go-scale"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/genvm/core"
"github.com/spacemeshos/go-spacemesh/genvm/sdk"
"github.com/spacemeshos/go-spacemesh/genvm/sdk/multisig"
"github.com/spacemeshos/go-spacemesh/genvm/templates/vesting"
)
type Aggregator = multisig.Aggregator
var (
NewAggregator = multisig.NewAggregator
SelfSpawn = multisig.SelfSpawn
Spawn = multisig.Spawn
Spend = multisig.Spend
)
// DrainVault creates drain vault transaction.
func DrainVault(
ref uint8,
pk ed25519.PrivateKey,
principal, vault, receiver types.Address,
amount uint64,
nonce core.Nonce,
opts ...sdk.Opt,
) *Aggregator {
options := sdk.Defaults()
for _, opt := range opts {
opt(options)
}
payload := core.Payload{}
payload.Nonce = nonce
payload.GasPrice = options.GasPrice
args := vesting.DrainVaultArguments{
Vault: vault,
}
args.Destination = receiver
args.Amount = amount
method := scale.U8(vesting.MethodDrainVault)
tx := sdk.Encode(&sdk.TxVersion, &principal, &method, &payload, &args)
sig := ed25519.Sign(ed25519.PrivateKey(pk), core.SigningBody(options.GenesisID[:], tx))
aggregator := NewAggregator(tx)
part := vesting.Part{Ref: ref}
copy(part.Sig[:], sig)
aggregator.Add(part)
return aggregator
}