Skip to content

Commit

Permalink
better error messages for ledger transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Oct 15, 2024
1 parent 8c4677d commit 1919d54
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 158 deletions.
143 changes: 83 additions & 60 deletions lib/go/templates/internal/assets/assets.go

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions lib/go/templates/manifest.mainnet.json

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions lib/go/templates/manifest.testnet.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions transactions/idTableStaking/scripts/get_moves_pending.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import FlowIDTableStaking from "FlowIDTableStaking"

// This script returns the current moves pending list
access(all) fun main(): {String: {UInt32: Bool}} {
return FlowIDTableStaking.getMovesPendingList()!
}
8 changes: 6 additions & 2 deletions transactions/lockedTokens/user/deposit_tokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ transaction(amount: UFix64) {

prepare(acct: auth(BorrowValue) &Account) {
self.holderRef = acct.storage.borrow<&LockedTokens.TokenHolder>(from: LockedTokens.TokenHolderStoragePath)
?? panic("The primary user account does not have an associated locked account")
?? panic("Cannot deposit tokens to a locked account! The signer of the transaction "
.concat("does not have an associated locked account, ")
.concat("so there is nowhere to deposit the tokens."))

self.vaultRef = acct.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow flow token vault ref")
?? panic("The signer does not store a FlowToken Vault object at the path "
.concat("/storage/flowTokenVault. ")
.concat("The signer must initialize their account with this vault first!"))
}

execute {
Expand Down
8 changes: 6 additions & 2 deletions transactions/lockedTokens/user/withdraw_tokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ transaction(amount: UFix64) {

prepare(acct: auth(BorrowValue) &Account) {
self.holderRef = acct.storage.borrow<auth(LockedTokens.TokenOperations, FungibleToken.Withdraw) &LockedTokens.TokenHolder>(from: LockedTokens.TokenHolderStoragePath)
?? panic("The primary user account does not have an associated locked account")
?? panic("Cannot withdraw locked tokens! The signer of the transaction "
.concat("does not have an associated locked account, ")
.concat("so there are no locked tokens to withdraw."))

self.vaultRef = acct.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow flow token vault ref")
?? panic("The signer does not store a FlowToken Vault object at the path "
.concat("/storage/flowTokenVault. ")
.concat("The signer must initialize their account with this vault first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/close_stake.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ transaction(nodeID: String, delegatorID: UInt32?) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
15 changes: 12 additions & 3 deletions transactions/stakingCollection/create_machine_account.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ transaction(nodeID: String,

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))

if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {
let sigAlgo = SignatureAlgorithm(rawValue: machineAccountKeySignatureAlgorithm)
?? panic("Could not get a signature algorithm from the raw enum value provided")
?? panic("Cannot create machine account with provided key: Must provide a signature algorithm raw value that corresponds to "
.concat("one of the available signature algorithms for Flow keys.")
.concat("You provided ").concat(machineAccountKeySignatureAlgorithm.toString())
.concat(" but the options are either 1 (ECDSA_P256), 2 (ECDSA_secp256k1), or 3 (BLS_BLS12_381)."))

let hashAlgo = HashAlgorithm(rawValue: machineAccountKeyHashAlgorithm)
?? panic("Could not get a hash algorithm from the raw enum value provided")
?? panic("Cannot create machine account with provided key: Must provide a hash algorithm raw value that corresponds to "
.concat("one of of the available hash algorithms for Flow keys.")
.concat("You provided ").concat(machineAccountKeyHashAlgorithm.toString())
.concat(" but the options are 1 (SHA2_256), 2 (SHA2_384), 3 (SHA3_256), ")
.concat("4 (SHA3_384), 5 (KMAC128_BLS_BLS12_381), or 6 (KECCAK_256)."))

let publicKey = PublicKey(
publicKey: machineAccountKey.decodeHex(),
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/register_delegator.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ transaction(id: String, amount: UFix64) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first in order to register!"))
}

execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ transaction(ids: [String], amounts: [UFix64]) {

prepare(account: auth(BorrowValue) &Account) {
self.stakingCollectionRef = account.storage.borrow<auth(FlowStakingCollection.CollectionOwner) &FlowStakingCollection.StakingCollection>(from: FlowStakingCollection.StakingCollectionStoragePath)
?? panic("Could not borrow ref to StakingCollection")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/register_multiple_nodes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ transaction(ids: [String],

prepare(account: auth(BorrowValue) &Account) {
self.stakingCollectionRef = account.storage.borrow<auth(FlowStakingCollection.CollectionOwner) &FlowStakingCollection.StakingCollection>(from: FlowStakingCollection.StakingCollectionStoragePath)
?? panic("Could not borrow ref to StakingCollection")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))

var i = 0

Expand Down
15 changes: 12 additions & 3 deletions transactions/stakingCollection/register_node.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ transaction(id: String,

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first in order to register!"))

if let machineAccount = self.stakingCollectionRef.registerNode(
id: id,
Expand All @@ -30,10 +32,17 @@ transaction(id: String,
payer: account
) {
let sigAlgo = SignatureAlgorithm(rawValue: machineAccountKeySignatureAlgorithm)
?? panic("Could not get a signature algorithm from the raw enum value provided")
?? panic("Cannot register node with provided machine account key: Must provide a signature algorithm raw value that corresponds to "
.concat("one of the available signature algorithms for Flow keys.")
.concat("You provided ").concat(machineAccountKeySignatureAlgorithm.toString())
.concat(" but the options are either 1 (ECDSA_P256), 2 (ECDSA_secp256k1), or 3 (BLS_BLS12_381)."))

let hashAlgo = HashAlgorithm(rawValue: machineAccountKeyHashAlgorithm)
?? panic("Could not get a hash algorithm from the raw enum value provided")
?? panic("Cannot register node with the provided machine account key: Must provide a hash algorithm raw value that corresponds to "
.concat("one of of the available hash algorithms for Flow keys.")
.concat("You provided ").concat(machineAccountKeyHashAlgorithm.toString())
.concat(" but the options are 1 (SHA2_256), 2 (SHA2_384), 3 (SHA3_256), ")
.concat("4 (SHA3_384), 5 (KMAC128_BLS_BLS12_381), or 6 (KECCAK_256)."))

let publicKey = PublicKey(
publicKey: machineAccountKey.decodeHex(),
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/request_unstaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ transaction(nodeID: String, delegatorID: UInt32?, amount: UFix64) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/restake_all_stakers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ transaction {

prepare(account: auth(BorrowValue) &Account) {
self.stakingCollectionRef = account.storage.borrow<auth(FlowStakingCollection.CollectionOwner) &FlowStakingCollection.StakingCollection>(from: FlowStakingCollection.StakingCollectionStoragePath)
?? panic("Could not borrow ref to StakingCollection")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/stake_new_tokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ transaction(nodeID: String, delegatorID: UInt32?, amount: UFix64) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/stake_rewarded_tokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ transaction(nodeID: String, delegatorID: UInt32?, amount: UFix64) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/stake_unstaked_tokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ transaction(nodeID: String, delegatorID: UInt32?, amount: UFix64) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
10 changes: 7 additions & 3 deletions transactions/stakingCollection/transfer_delegator.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ transaction(nodeID: String, delegatorID: UInt32, to: Address) {
prepare(account: auth(BorrowValue) &Account) {
// The account to transfer the NodeDelegator object to must have a valid Staking Collection in order to receive the NodeDelegator.
if (!FlowStakingCollection.doesAccountHaveStakingCollection(address: to)) {
panic("Destination account must have a Staking Collection set up.")
panic("The desination account does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The destination account must initialize their account with this object first!"))
}

// Get a reference to the authorizers StakingCollection
self.fromStakingCollectionRef = 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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))

// Get the PublicAccount of the account to transfer the NodeDelegator to.
let toAccount = getAccount(to)

// Borrow a capability to the public methods available on the receivers StakingCollection.
self.toStakingCollectionCap = toAccount.capabilities
.borrow<&FlowStakingCollection.StakingCollection>(FlowStakingCollection.StakingCollectionPublicPath)
?? panic("Could not borrow a referamce to a StakingCollection in the receiver's account")
?? panic("Could not borrow a reference to a StakingCollection in the receiver's account")
}

execute {
Expand Down
12 changes: 9 additions & 3 deletions transactions/stakingCollection/transfer_node.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ transaction(nodeID: String, to: Address) {
prepare(account: auth(BorrowValue) &Account) {
// The account to transfer the NodeStaker object to must have a valid Staking Collection in order to receive the NodeStaker.
if (!FlowStakingCollection.doesAccountHaveStakingCollection(address: to)) {
panic("Destination account must have a Staking Collection set up.")
panic("The desination account does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The destination account must initialize their account with this object first!"))
}

// Get a reference to the authorizers StakingCollection
self.fromStakingCollectionRef = 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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))

// Get the PublicAccount of the account to transfer the NodeStaker to.
let toAccount = getAccount(to)
Expand All @@ -27,7 +31,9 @@ transaction(nodeID: String, to: Address) {
?? panic("Could not borrow a reference to a StakingCollection in the receiver's account")

let machineAccountInfo = self.fromStakingCollectionRef.getMachineAccounts()[nodeID]
?? panic("Could not get machine account info for the specified node ID")
?? panic("Could not get machine account info from the signer's account for the node ID "
.concat(nodeID).concat(". Make sure that the node has configured a machine account ")
.concat("and has it registered in the staking collection."))

// Remove the NodeStaker from the authorizers StakingCollection.
let nodeStaker <- self.fromStakingCollectionRef.removeNode(nodeID: nodeID)
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/unstake_all.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ transaction(nodeID: String) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
4 changes: 3 additions & 1 deletion transactions/stakingCollection/update_networking_address.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ transaction(nodeID: String, newAddress: String) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ transaction(nodeID: String, amount: UFix64) {

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")
?? panic("The signer does not store a Staking Collection object at the path "
.concat(FlowStakingCollection.StakingCollectionStoragePath.toString())
.concat(". The signer must initialize their account with this object first!"))
}

execute {
Expand Down
Loading

0 comments on commit 1919d54

Please sign in to comment.