onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://cadence-lang.org
Apache License 2.0
534 stars 138 forks source link

Add ability to get address of account running transaction within the contract function #359

Closed alxocity closed 1 month ago

alxocity commented 4 years ago

Issue To Be Solved

Currently the only way to detect the account running a function is for them to pass their AuthAccount (bad) or send in a resource reference from their collection (tedious).

Suggest A Solution

Would be nice to have a "sender" like in solidity

or

Have some syntactical sugar for this boilerplate code:

// Contract snippet
pub resource Author { }
pub fun createAuthor(): @Author {
  return <-create Author()
}
pub fun mintNFT(author: &Author): @NFT {
  return <-create NFT(author: author.owner!.address)
}
// Transaction snippet
acct.save(<-NFT.createAuthor(), to: /storage/NFTAuthor)
let authorRef = acct.borrow<&NFT.Author>(from: /storage/NFTAuthor)!
let nft <- NFT.mintNFT(author: authorRef)
destroy <-acct.load<@NFT.Author>(from: /storage/NFTAuthor)
bjartek commented 4 years ago

Why can you not send in their Address manually as a parameter to the script/transaction?

alxocity commented 4 years ago

@bjartek anyone can impersonate anyone else in that case

bjartek commented 4 years ago

And the AuthAccount is bad because you really do not want access to their private stuff?

So what you kind of want is a PublicAccount that is an proposer that has signed the payload?

turbolent commented 1 month ago

An equivalent is intentionally not supported, see https://cadence-lang.org/docs/solidity-to-cadence#msgsender-considered-harmful