/
register_node.cdc
45 lines (38 loc) · 1.91 KB
/
register_node.cdc
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
import Crypto
import FlowStakingCollection from "FlowStakingCollection"
/// Registers a delegator in the staking collection resource
/// for the specified node information and the amount of tokens to commit
transaction(id: String,
role: UInt8,
networkingAddress: String,
networkingKey: String,
stakingKey: String,
amount: UFix64,
machineAccountKey: String,
machineAccountKeySignatureAlgorithm: UInt8,
machineAccountKeyHashAlgorithm: UInt8) {
let stakingCollectionRef: auth(FlowStakingCollection.CollectionOwner) &FlowStakingCollection.StakingCollection
prepare(account: auth(BorrowValue) &Account) {
self.stakingCollectionRef = account.storage.borrow<auth(FlowStakingCollection.CollectionOwner) &FlowStakingCollection.StakingCollection>(from: FlowStakingCollection.StakingCollectionStoragePath)
?? panic("Could not borrow a reference to a StakingCollection in the primary user's account")
if let machineAccount = self.stakingCollectionRef.registerNode(
id: id,
role: role,
networkingAddress: networkingAddress,
networkingKey: networkingKey,
stakingKey: stakingKey,
amount: amount,
payer: account
) {
let sigAlgo = SignatureAlgorithm(rawValue: machineAccountKeySignatureAlgorithm)
?? panic("Could not get a signature algorithm from the raw enum value provided")
let hashAlgo = HashAlgorithm(rawValue: machineAccountKeyHashAlgorithm)
?? panic("Could not get a hash algorithm from the raw enum value provided")
let publicKey = PublicKey(
publicKey: machineAccountKey.decodeHex(),
signatureAlgorithm: sigAlgo
)
machineAccount.keys.add(publicKey: publicKey, hashAlgorithm: hashAlgo, weight: 1000.0)
}
}
}