Add Current.x reference page to the docs
This commit is contained in:
parent
59448e1d91
commit
a0c2978b9f
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
id: current-reference
|
id: current-reference
|
||||||
title: Current
|
title: Current - Things relating to the current execution context
|
||||||
---
|
---
|
||||||
|
|
||||||
## Current.balance() : tez
|
## Current.balance() : tez
|
||||||
@ -149,17 +149,87 @@ let check_ = (p: unit) : int =>
|
|||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
## Current.gas()
|
|
||||||
|
|
||||||
## Current.sender() : address
|
## Current.sender() : address
|
||||||
|
|
||||||
Get the address that initiated the current transaction.
|
Get the address that initiated the current transaction.
|
||||||
|
|
||||||
## Current.address
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
## Current.self_address
|
<!--PascaLIGO-->
|
||||||
|
```pascaligo
|
||||||
|
function main (const p: unit) : address is sender
|
||||||
|
```
|
||||||
|
|
||||||
## Current.implicit_account
|
<!--CameLIGO-->
|
||||||
|
```cameligo
|
||||||
|
let main (p: unit) : address = Current.sender
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
```reasonligo
|
||||||
|
let main = (p: unit) : address => Current.sender;
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
## Current.address(c: a' contract) : address
|
||||||
|
|
||||||
|
Get the address associated with a `contract`.
|
||||||
|
|
||||||
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
<!--PascaLIGO-->
|
||||||
|
```pascaligo
|
||||||
|
function main (const p : key_hash) : address is block {
|
||||||
|
const c : contract(unit) = implicit_account(p) ;
|
||||||
|
} with address(c)
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--CameLIGO-->
|
||||||
|
```cameligo
|
||||||
|
let main (p : key_hash) =
|
||||||
|
let c : unit contract = Current.implicit_account p in
|
||||||
|
Current.address c
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
```reasonligo
|
||||||
|
let main = (p : key_hash) : address => {
|
||||||
|
let c : contract(unit) = Current.implicit_account(p) ;
|
||||||
|
Current.address(c) ;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
## Current.self_address() : address
|
||||||
|
|
||||||
|
Get the address of the currently running contract.
|
||||||
|
|
||||||
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
<!--PascaLIGO-->
|
||||||
|
```pascaligo
|
||||||
|
function main (const p: unit) : address is self_address
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--CameLIGO-->
|
||||||
|
```cameligo
|
||||||
|
let main (p: unit) : address = Current.self_address
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
```reasonligo
|
||||||
|
let main = (p: unit): address => Current.self_address;
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
## Current.implicit_account(p: key_hash) : a' contract
|
||||||
|
|
||||||
|
Get the default contract associated with an on-chain keypair. This contract
|
||||||
|
doesn't execute code, instead it exists to receive money on behalf of a keys
|
||||||
|
owner.
|
||||||
|
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
@ -180,9 +250,44 @@ let main = (kh: key_hash): contract(unit) => Current.implicit_account(kh);
|
|||||||
|
|
||||||
<!--END_DOCUSAURUS_CODE_TABS-->
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
## Current.source
|
## Current.source() : address
|
||||||
|
|
||||||
## Current.failwith
|
Get the _originator_ of the current transaction. That is, if a chain of transactions
|
||||||
|
led to the current execution get the address that began the chain. Not to be confused
|
||||||
|
with `Current.sender`, which gives the address of the contract or user which directly
|
||||||
|
caused the current transaction.
|
||||||
|
|
||||||
|
> ⚠️
|
||||||
|
> There are a few caveats you should keep in mind before using `SOURCE` over `SENDER`:
|
||||||
|
>
|
||||||
|
> 1. SOURCE will never be a contract, so if you want to allow contracts (multisigs etc) to operate your contract, you need to use SENDER
|
||||||
|
> 2. https://vessenes.com/tx-origin-and-ethereum-oh-my/ -- in general it is somewhat unsafe to assume that SOURCE understands everything that's going to happen in a transaction. If SOURCE transfers to a malicious (or sufficiently attackable) contract, that contract might potentially transfer to yours, without SOURCE's consent. So if you are using SOURCE for authentication, you risk being confused. A good historical example of this is bakers paying out delegation rewards. Naive bakers did (and probably still do) just use tezos-client to transfer to whatever KT1 delegates they had, even if those KT1 were malicious scripts.
|
||||||
|
|
||||||
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
<!--PascaLIGO-->
|
||||||
|
```pascaligo
|
||||||
|
function main (const p: unit) : address is source
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--CameLIGO-->
|
||||||
|
```cameligo
|
||||||
|
let main (p: unit) : address = Current.source
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--ReasonLIGO-->
|
||||||
|
```reasonligo
|
||||||
|
let main = (p: unit) : address => Current.source;
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--END_DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
## Current.failwith(error_message: string) : a'
|
||||||
|
|
||||||
|
Cause the contract to fail with an error message.
|
||||||
|
|
||||||
|
> ⚠ Using this currently requires a type annotation on the failwith to unify it
|
||||||
|
> with the type of whatever other code branch it's on.
|
||||||
|
|
||||||
<!--DOCUSAURUS_CODE_TABS-->
|
<!--DOCUSAURUS_CODE_TABS-->
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user