Add Chain.network_id

This commit is contained in:
Hans Svensson 2023-06-22 09:13:49 +02:00
parent c3788b2b5a
commit 527bca4917
6 changed files with 20 additions and 3 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`Bytes.to_fixed_size`, `Bytes.to_any_size`, `Bytes.size`, `String.to_bytes`, `Bytes.to_fixed_size`, `Bytes.to_any_size`, `Bytes.size`, `String.to_bytes`,
and `Int.to_bytes`; and adjust `Bytes.concat` to allow both fixed and arbitrary and `Int.to_bytes`; and adjust `Bytes.concat` to allow both fixed and arbitrary
sized byte arrays. sized byte arrays.
- `Chain.network_id` - a function to get hold of the Chain's network id.
### Changed ### Changed
### Removed ### Removed
- `Bitwise.aes` standard library is removed - the builtin operations are superior. - `Bitwise.aes` standard library is removed - the builtin operations are superior.

View File

@ -734,6 +734,14 @@ Chain.gas_limit : int
The gas limit of the current block. The gas limit of the current block.
##### network\_id
```
Chain.network\_id : string
```
The network id of the chain.
##### spend ##### spend
``` ```
Chain.spend(to : address, amount : int) : unit Chain.spend(to : address, amount : int) : unit

View File

@ -654,6 +654,7 @@ global_env() ->
{"block_height", Int}, {"block_height", Int},
{"difficulty", Int}, {"difficulty", Int},
{"gas_limit", Int}, {"gas_limit", Int},
{"network_id", String},
{"bytecode_hash",FunC1(bytecode_hash, A, Option(Hash))}, {"bytecode_hash",FunC1(bytecode_hash, A, Option(Hash))},
{"create", Stateful( {"create", Stateful(
FunN([ {named_arg_t, Ann, {id, Ann, "value"}, Int, {typed, Ann, {int, Ann, 0}, Int}} FunN([ {named_arg_t, Ann, {id, Ann, "value"}, Int, {typed, Ann, {int, Ann, 0}, Int}}

View File

@ -271,8 +271,8 @@ builtins() ->
end, end,
Scopes = [{[], [{"abort", 1}, {"require", 2}, {"exit", 1}]}, Scopes = [{[], [{"abort", 1}, {"require", 2}, {"exit", 1}]},
{["Chain"], [{"spend", 2}, {"balance", 1}, {"block_hash", 1}, {"coinbase", none}, {["Chain"], [{"spend", 2}, {"balance", 1}, {"block_hash", 1}, {"coinbase", none},
{"timestamp", none}, {"block_height", none}, {"difficulty", none}, {"timestamp", none}, {"block_height", none}, {"difficulty", none}, {"gas_limit", none},
{"gas_limit", none}, {"bytecode_hash", 1}, {"create", variable}, {"clone", variable}]}, {"network_id", none}, {"bytecode_hash", 1}, {"create", variable}, {"clone", variable}]},
{["Contract"], [{"address", none}, {"balance", none}, {"creator", none}]}, {["Contract"], [{"address", none}, {"balance", none}, {"creator", none}]},
{["Call"], [{"origin", none}, {"caller", none}, {"value", none}, {"gas_price", none}, {"fee", none}, {["Call"], [{"origin", none}, {"caller", none}, {"value", none}, {"gas_price", none}, {"fee", none},
{"gas_left", 0}]}, {"gas_left", 0}]},

View File

@ -568,6 +568,8 @@ builtin_to_scode(_Env, chain_difficulty, []) ->
[aeb_fate_ops:difficulty(?a)]; [aeb_fate_ops:difficulty(?a)];
builtin_to_scode(_Env, chain_gas_limit, []) -> builtin_to_scode(_Env, chain_gas_limit, []) ->
[aeb_fate_ops:gaslimit(?a)]; [aeb_fate_ops:gaslimit(?a)];
builtin_to_scode(_Env, chain_network_id, []) ->
[aeb_fate_ops:network_id(?a)];
builtin_to_scode(_Env, contract_balance, []) -> builtin_to_scode(_Env, contract_balance, []) ->
[aeb_fate_ops:balance(?a)]; [aeb_fate_ops:balance(?a)];
builtin_to_scode(_Env, contract_address, []) -> builtin_to_scode(_Env, contract_address, []) ->
@ -1090,6 +1092,7 @@ attributes(I) ->
{'MICROBLOCK', A} -> Pure(A, []); {'MICROBLOCK', A} -> Pure(A, []);
{'DIFFICULTY', A} -> Pure(A, []); {'DIFFICULTY', A} -> Pure(A, []);
{'GASLIMIT', A} -> Pure(A, []); {'GASLIMIT', A} -> Pure(A, []);
{'NETWORK_ID', A} -> Pure(A, []);
{'GAS', A} -> Pure(A, []); {'GAS', A} -> Pure(A, []);
{'LOG0', A} -> Impure(none, [A]); {'LOG0', A} -> Impure(none, [A]);
{'LOG1', A, B} -> Impure(none, [A, B]); {'LOG1', A, B} -> Impure(none, [A, B]);

View File

@ -2,7 +2,8 @@
contract ChainTest = contract ChainTest =
record state = { last_bf : address } record state = { last_bf : address
, nw_id : string }
function init() : state = function init() : state =
{last_bf = Contract.address} {last_bf = Contract.address}
@ -11,3 +12,6 @@ contract ChainTest =
function save_coinbase() = function save_coinbase() =
put(state{last_bf = Chain.coinbase}) put(state{last_bf = Chain.coinbase})
function save_network_id() =
put(state{nw_id = Chain.network_id})