Skip to content

Commit

Permalink
made setup and create private forwarder nilpotent (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik authored Mar 25, 2021
1 parent 32371bd commit c33ffee
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions lib/go/test/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,39 @@ func TestPrivateForwarder(t *testing.T) {
)

})

t.Run("Should be able to do account setup a second time without change", func(t *testing.T) {

script := templates.GenerateSetupAccountPrivateForwarderScript(
fungibleAddr,
exampleTokenAddr,
exampleTokenAddr,
"ExampleToken",
)

// send the same transaction one more time for the same address that's already set up
tx := flow.NewTransaction().
SetScript(script).
SetGasLimit(100).
SetProposalKey(
b.ServiceKey().Address,
b.ServiceKey().Index,
b.ServiceKey().SequenceNumber,
).
SetPayer(b.ServiceKey().Address).
AddAuthorizer(joshAddress)

signAndSubmit(
t, b, tx,
[]flow.Address{
b.ServiceKey().Address,
joshAddress,
},
[]crypto.Signer{
b.ServiceKey().Signer(),
joshSigner,
},
false,
)
})
}
4 changes: 4 additions & 0 deletions transactions/privateForwarder/setup_and_create_forwarder.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import PrivateReceiverForwarder from 0xPRIVATEFORWARDINGADDRESS
transaction {

prepare(signer: AuthAccount) {
if signer.getCapability<&PrivateReceiverForwarder.Forwarder>(PrivateReceiverForwarder.PrivateReceiverPublicPath).check() {
// private forwarder was already set up
return
}

if signer.borrow<&ExampleToken.Vault>(from: /storage/exampleTokenVault) == nil {
// Create a new ExampleToken Vault and put it in storage
Expand Down

0 comments on commit c33ffee

Please sign in to comment.