Skip to content

Commit

Permalink
Update custom_account_setup_qa.cdc
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Jun 8, 2022
1 parent c710c39 commit 92571b7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions custom_account_setup_qa.cdc
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import NonFungibleToken from 0x631e88ae7f1d7c20
import Electables from 0x4c05c3d3499ca274
import Crypto

transaction(publicKeys: [String], contracts: {String: String}) {
transaction(publicKeys: [Crypto.KeyListEntry], contracts: {String: String}) {
prepare(signer: AuthAccount) {
let acct = AuthAccount(payer: signer)
let account = AuthAccount(payer: signer)

// add all the keys to the account
for key in publicKeys {
acct.addPublicKey(key.decodeHex())
account.keys.add(publicKey: key.publicKey, hashAlgorithm: key.hashAlgorithm, weight: key.weight)
}

// add contracts if provided
for contract in contracts.keys {
acct.contracts.add(name: contract, code: contracts[contract]!.decodeHex())
account.contracts.add(name: contract, code: contracts[contract]!.decodeHex())
}

if acct.borrow<&Electables.Collection>(from: Electables.CollectionStoragePath) == nil {
if account.borrow<&Electables.Collection>(from: Electables.CollectionStoragePath) == nil {
// create a new empty collection
let collection <- Electables.createEmptyCollection()

// save it to the account
acct.save(<- collection, to: Electables.CollectionStoragePath)
account.save(<- collection, to: Electables.CollectionStoragePath)

// Creates a public capability for the collection so that other users can publicly access electable attributes.
// The pieces inside of the brackets specify the type of the linked object, and only expose the fields and
// functions on those types.
acct.link<&Electables.Collection{NonFungibleToken.CollectionPublic, Electables.ElectablesPublicCollection}>(
account.link<&Electables.Collection{NonFungibleToken.CollectionPublic, Electables.ElectablesPublicCollection}>(
Electables.CollectionPublicPath, target: Electables.CollectionStoragePath
)
}
Expand Down

0 comments on commit 92571b7

Please sign in to comment.