Skip to content

Commit

Permalink
questions on access
Browse files Browse the repository at this point in the history
  • Loading branch information
whalelephant committed Aug 11, 2021
1 parent 8149a8c commit fa84e34
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 5 deletions.
36 changes: 36 additions & 0 deletions lib/go/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,39 @@ func MultiSig_VaultExecuteTx(
events = util.ParseTestEvents(e)
return
}

func MultiSig_PubUpdateTxIndex(
g *gwtf.GoWithTheFlow,
index uint64,
payerAcct string,
vaultAcct string,
) (events []*gwtf.FormatedEvent, err error) {
txFilename := "../../../transactions/pubUpdateTxIndex.cdc"
txScript := util.ParseCadenceTemplate(txFilename)

e, err := g.TransactionFromFile(txFilename, txScript).
SignProposeAndPayAs(payerAcct).
AccountArgument(vaultAcct).
UInt64Argument(index).
Run()
events = util.ParseTestEvents(e)
return
}

func MultiSig_PubUpdateStore(
g *gwtf.GoWithTheFlow,
index uint64,
payerAcct string,
vaultAcct string,
) (events []*gwtf.FormatedEvent, err error) {
txFilename := "../../../transactions/pubUpdateStore.cdc"
txScript := util.ParseCadenceTemplate(txFilename)

e, err := g.TransactionFromFile(txFilename, txScript).
SignProposeAndPayAs(payerAcct).
AccountArgument(vaultAcct).
UInt64Argument(index).
Run()
events = util.ParseTestEvents(e)
return
}
28 changes: 28 additions & 0 deletions lib/go/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,31 @@ func TestExecutePayloadWithMultipleSig(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, transferAmount, (initFromBalance - postFromBalance).String())
}

func TestPubUpdateTxIndex(t *testing.T) {
g := gwtf.NewGoWithTheFlow("../../../flow.json")
payerAcct := "owner"
vaultAcct := "vaulted-account"

_, err := MultiSig_PubUpdateTxIndex(g, 11, payerAcct, vaultAcct)
// error: cannot assign to unassignable expression
// --> cc200f93812741ff8731fe90ba0685f70ca942c9bbd62318245e1c9c4ea9bfdd:17:8
// |
// 17 | vaultRef.signatureStore!.txIndex = txIndex
// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
assert.Error(t, err)
}

func TestPubUpdateStore(t *testing.T) {
g := gwtf.NewGoWithTheFlow("../../../flow.json")
payerAcct := "owner"
vaultAcct := "vaulted-account"

_, err := MultiSig_PubUpdateStore(g, 11, payerAcct, vaultAcct)
// error: cannot assign to `signatureStore`: field has public access
// --> f59dda20ccec82c40041048f66b938be0de7e3c8740f87f432ff979d42100c7b:19:17
// |
// | vaultRef.signatureStore = store
// | ^^^^^^^^^^^^^^ consider making it publicly settable with `pub(set)`
assert.Error(t, err)
}
5 changes: 0 additions & 5 deletions scripts/get_block.cdc

This file was deleted.

21 changes: 21 additions & 0 deletions transactions/pubUpdateStore.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import MultiSigFlowToken from 0x{{.MultiSigFlowToken}}
import OnChainMultiSig from 0x{{.OnChainMultiSig}}

transaction (multiSigVaultAddr: Address, txIndex: UInt64) {
prepare(payer: AuthAccount) {
}

execute {
// Get the account of where the multisig vault is
let acct = getAccount(multiSigVaultAddr)

// Get the capability to try to execute a transaction that has a payload presigned by multiple parties
let vaultRef = acct.getCapability(MultiSigFlowToken.VaultPubSigner)
.borrow<&MultiSigFlowToken.Vault{OnChainMultiSig.PublicSigner}>()
?? panic("Could not borrow vault pub sig reference")

let store = vaultRef.signatureStore!
store.txIndex = txIndex
vaultRef.signatureStore = store
}
}
19 changes: 19 additions & 0 deletions transactions/pubUpdateTxIndex.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import MultiSigFlowToken from 0x{{.MultiSigFlowToken}}
import OnChainMultiSig from 0x{{.OnChainMultiSig}}

transaction (multiSigVaultAddr: Address, txIndex: UInt64) {
prepare(payer: AuthAccount) {
}

execute {
// Get the account of where the multisig vault is
let acct = getAccount(multiSigVaultAddr)

// Get the capability to try to execute a transaction that has a payload presigned by multiple parties
let vaultRef = acct.getCapability(MultiSigFlowToken.VaultPubSigner)
.borrow<&MultiSigFlowToken.Vault{OnChainMultiSig.PublicSigner}>()
?? panic("Could not borrow vault pub sig reference")

vaultRef.signatureStore!.txIndex = txIndex
}
}

0 comments on commit fa84e34

Please sign in to comment.