From b7289dfadd217d0777609403a984b167a5614c6b Mon Sep 17 00:00:00 2001 From: Nikita Fuchs Date: Sat, 10 Oct 2020 14:19:10 +0200 Subject: [PATCH] fixes hans marked to do, fix broken sophia.md references --- docs/docs/contracts.md | 49 +----------------------------------- docs/docs/sophia_stdlib.md | 14 +++++------ docs/sophia.md | 51 +------------------------------------- 3 files changed, 8 insertions(+), 106 deletions(-) diff --git a/docs/docs/contracts.md b/docs/docs/contracts.md index 887eb24..869152c 100644 --- a/docs/docs/contracts.md +++ b/docs/docs/contracts.md @@ -174,7 +174,7 @@ If in doubt, it is possible to check if an address is payable using #### Payable entrypoints A contract entrypoint is by default *not* payable. Any call to such a function -(either a [Remote call](contracts.md#calling-other-contracts) or a contract call transaction) +(either a [Remote call](#calling-other-contracts) or a contract call transaction) that has a non-zero `value` will fail. Contract entrypoints that should be called with a non-zero value should be declared `payable`. @@ -504,15 +504,6 @@ the hash functions described below. Please refer to the `String` [library documentation](sophia_stdlib.md#String). -### Chars - -There is a builtin type `char` (the underlying representation being an integer), -mainly used to manipulate strings via `String.to_list`/`String.from_list`. - -Characters can also be introduced as character literals (`'x', '+', ...). - -Please refer to the `Char` [library documentation](sophia_stdlib.md#Char). - ### Byte arrays Byte arrays are fixed size arrays of 8-bit integers. They are described in hexadecimal system, @@ -617,44 +608,6 @@ Contracts can interact with the [Aeternity Naming System](https://github.com/aeternity/protocol/blob/master/AENS.md). For this purpose the [AENS](sophia_stdlib.md#AENS) library was exposed. -#### Example - -In this example we assume that the name `name` already exists, and is owned by -an account with address `addr`. In order to allow a contract `ct` to handle -`name` the account holder needs to create a -[signature](examples.md#delegation-signature) `sig` of `addr | name.hash | ct.address`. - -Armed with this information we can for example write a function that extends -the name if it expires within 1000 blocks: -``` - stateful entrypoint extend_if_necessary(addr : address, name : string, sig : signature) = - switch(AENS.lookup(name)) - None => () - Some(AENS.Name(_, FixedTTL(expiry), _)) => - if(Chain.block_height + 1000 > expiry) - AENS.update(addr, name, Some(RelativeTTL(50000)), None, None, signature = sig) -``` - -And we can write functions that adds and removes keys from the pointers of the -name: -``` - stateful entrypoint add_key(addr : address, name : string, key : string, - pt : AENS.pointee, sig : signature) = - switch(AENS.lookup(name)) - None => () - Some(AENS.Name(_, _, ptrs)) => - AENS.update(addr, name, None, None, Some(ptrs{[key] = pt}), signature = sig) - - stateful entrypoint delete_key(addr : address, name : string, - key : string, sig : signature) = - switch(AENS.lookup(name)) - None => () - Some(AENS.Name(_, _, ptrs)) => - let ptrs = Map.delete(key, ptrs) - AENS.update(addr, name, None, None, Some(ptrs), signature = sig) -``` - - ### Events Sophia contracts log structured messages to an event log in the resulting diff --git a/docs/docs/sophia_stdlib.md b/docs/docs/sophia_stdlib.md index 225c5f3..ec7e49c 100644 --- a/docs/docs/sophia_stdlib.md +++ b/docs/docs/sophia_stdlib.md @@ -14,7 +14,6 @@ The out-of-the-box namespaces are: - [Bits](#Bits) - [Bytes](#Bytes) -- [Char](#Char) - [Int](#Int) - [Map](#Map) - [Address](#Address) @@ -152,7 +151,6 @@ Bytes.split(a : bytes(m + n)) : bytes(m) * bytes(n) Splits a byte array at given index -## Char #### to_int ``` @@ -348,7 +346,7 @@ Registers new oracle answering questions of type `'a` with answers of type `'b`. * The `acct` is the address of the oracle to register (can be the same as the contract). * `signature` is a signature proving that the contract is allowed to register the account - the account address + the contract address (concatenated as byte arrays) is - [signed](./sophia.md#delegation-signature) with the + [signed](./examples.md#delegation-signature) with the private key of the account, proving you have the private key of the oracle to be. If the address is the same as the contract `sign` is ignored and can be left out entirely. * The `qfee` is the minimum query fee to be paid by a user when asking a question of the oracle. @@ -381,7 +379,7 @@ Responds to the question `q` on `o`. Unless the contract address is the same as the oracle address the `signature` (which is an optional, named argument) needs to be provided. Proving that we have the private key of the oracle by -[signing](./sophia.md#delegation-signature) the oracle query id + contract address +[signing](./examples.md#delegation-signature) the oracle query id + contract address #### extend @@ -505,7 +503,7 @@ let Some(Name(owner, FixedTTL(expiry), ptrs)) = AENS.lookup("example.chain") AENS.preclaim(owner : address, commitment_hash : hash, ) : unit ``` -The [signature](./sophia.md#delegation-signature) should be over `owner address` + `Contract.address` +The [signature](./examples.md#delegation-signature) should be over `owner address` + `Contract.address` (concatenated as byte arrays). @@ -514,7 +512,7 @@ The [signature](./sophia.md#delegation-signature) should be over `owner address` AENS.claim(owner : address, name : string, salt : int, name_fee : int, ) : unit ``` -The [signature](./sophia.md#delegation-signature) should be over `owner address` + `name_hash` + `Contract.address` +The [signature](./examples.md#delegation-signature) should be over `owner address` + `name_hash` + `Contract.address` using the private key of the `owner` account for signing. @@ -525,7 +523,7 @@ AENS.transfer(owner : address, new_owner : address, name : string, ) : unit Revokes the name to extend the ownership time. -The [signature](./sophia.md#delegation-signature) should be over `owner address` + `name_hash` + `Contract.address` +The [signature](./examples.md#delegation-signature) should be over `owner address` + `name_hash` + `Contract.address` using the private key of the `owner` account for signing. diff --git a/docs/sophia.md b/docs/sophia.md index 73b82a4..8bbeefc 100644 --- a/docs/sophia.md +++ b/docs/sophia.md @@ -30,7 +30,6 @@ - [Updating a value](#updating-a-value) - [Map implementation](#map-implementation) - [Strings](#strings) - - [Chars](#chars) - [Byte arrays](#byte-arrays) - [Cryptographic builtins](#cryptographic-builtins) - [AEVM note](#aevm-note) @@ -39,7 +38,6 @@ - [Example](#example) - [Sanity checks](#sanity-checks) - [AENS interface](#aens-interface) - - [Example](#example-1) - [Events](#events) - [Argument order](#argument-order) - [Compiler pragmas](#compiler-pragmas) @@ -250,7 +248,7 @@ If in doubt, it is possible to check if an address is payable using #### Payable entrypoints A contract entrypoint is by default *not* payable. Any call to such a function -(either a [Remote call](contracts.md#calling-other-contracts) or a contract call transaction) +(either a [Remote call](#calling-other-contracts) or a contract call transaction) that has a non-zero `value` will fail. Contract entrypoints that should be called with a non-zero value should be declared `payable`. @@ -577,15 +575,6 @@ the hash functions described below. Please refer to the `String` [library documentation](sophia_stdlib.md#String). -### Chars - -There is a builtin type `char` (the underlying representation being an integer), -mainly used to manipulate strings via `String.to_list`/`String.from_list`. - -Characters can also be introduced as character literals (`'x', '+', ...). - -Please refer to the `Char` [library documentation](sophia_stdlib.md#Char). - ### Byte arrays Byte arrays are fixed size arrays of 8-bit integers. They are described in hexadecimal system, @@ -690,44 +679,6 @@ Contracts can interact with the [Aeternity Naming System](https://github.com/aeternity/protocol/blob/master/AENS.md). For this purpose the [AENS](sophia_stdlib.md#AENS) library was exposed. -#### Example - -In this example we assume that the name `name` already exists, and is owned by -an account with address `addr`. In order to allow a contract `ct` to handle -`name` the account holder needs to create a -[signature](#delegation-signature) `sig` of `addr | name.hash | ct.address`. - -Armed with this information we can for example write a function that extends -the name if it expires within 1000 blocks: -``` - stateful entrypoint extend_if_necessary(addr : address, name : string, sig : signature) = - switch(AENS.lookup(name)) - None => () - Some(AENS.Name(_, FixedTTL(expiry), _)) => - if(Chain.block_height + 1000 > expiry) - AENS.update(addr, name, Some(RelativeTTL(50000)), None, None, signature = sig) -``` - -And we can write functions that adds and removes keys from the pointers of the -name: -``` - stateful entrypoint add_key(addr : address, name : string, key : string, - pt : AENS.pointee, sig : signature) = - switch(AENS.lookup(name)) - None => () - Some(AENS.Name(_, _, ptrs)) => - AENS.update(addr, name, None, None, Some(ptrs{[key] = pt}), signature = sig) - - stateful entrypoint delete_key(addr : address, name : string, - key : string, sig : signature) = - switch(AENS.lookup(name)) - None => () - Some(AENS.Name(_, _, ptrs)) => - let ptrs = Map.delete(key, ptrs) - AENS.update(addr, name, None, None, Some(ptrs), signature = sig) -``` - - ### Events Sophia contracts log structured messages to an event log in the resulting