{% hint style="warning" %} Is now in the development stage. {% endhint %}
There is a set of classes and functions in chain.hpp
and contract_base.hpp
for the interaction with the Echo chain.
Member of class account
.
You can get balance of account or contract in needed assets.
Option | Description | Example |
---|---|---|
string id |
triplet id of account or contract | 1.2.5646 or 1.11.165 |
string asset_id |
triplet asset id | 1.3.0 |
int64_t
- requested balance.
int64_t my_get_balance(string id, string asset_id)
{
account other(id);
return other.get_balance(asset_id);
}
Member of class contract_base
.
You can transfer assets from contract to the recipient.
Option | Description | Example |
---|---|---|
string to |
triplet id of account | 1.2.5646 |
string asset_id |
triplet asset id | 1.3.0 |
int64_t amount |
transferred amount | 100 |
void
void my_transfer(string to, string asset_id, int64_t amount)
{
transfer(to, asset_id, amount);
}
Member of class object
.
You can get property of object from echo chain.
Option | Description | Example |
---|---|---|
string id |
triplet id of object | 1.2.15 |
string request |
name of property | echorand_key |
string
- value of requested property.
string my_get_property(string id, string request)
{
object other(id);
return other.get_property(request);
}
Member of class contract_base
.
You can get asset id with which the contract was called.
uint64_t
- asset id with which the contract was called.
uint64_t my_get_call_asset_id()
{
return get_call_asset_id();
}
Static member of class chain
, in the namespace x86_64_contract
.
You can get block hash by number.
Option | Description | Example |
---|---|---|
uint32_t number |
number of block | 15445 |
string
- block hash.
string my_get_block_hash(uint32_t number)
{
return chain::get_block_hash(number);
}
Member of class contract_base
.
You can get the author of current block.
string
- block author id.
string my_get_block_author()
{
return get_block_author();
}
Member of class contract_base
.
You can get current gas limit.
uint64_t int
- current gas limit in 10^-8^ ECHO.
uint64_t int my_get_gas_limit()
{
return get_gas_limit();
}
Member of class contract_base
.
You can get current head block number.
uint32_t
- block number.
uint32_t my_get_block_number()
{
return get_block_number();
}
Member of class contract_base
.
You can get current head block timestamp.
uint32_t
- block timestamp in seconds.
uint32_t my_get_block_timestamp()
{
return get_block_timestamp();
}
Member of class contract_base
.
You can get send value for current contract call.
int64_t
- amount of send.
int64_t my_get_send_value()
{
return get_send_value();
}
Member of class contract_base
.
You can get sender for current contract call.
string
- triplet id of sender.
string my_get_sender()
{
return get_sender();
}
Member of class contract_base
.
You can get origin sender for current contract call.
string
- triplet id of sender.
string my_get_origin_sender()
{
return get_origin_sender();
}
Static member of class chain
, in the namespace x86_64_contract
.
You can get called contract id.
uint32_t
- id of contract.
uint32_t my_get_contract_id()
{
return chain::get_contract_id();
}
Member of class contract_base
.
You can get full contract id.
string
- triplet id of contract.
string my_get_full_contract_id()
{
return get_full_contract_id();
}
Member of class contract_object
.
You can call get storage variable from another x86-64 contract. For the get, you will need to pass the amount by 0, count of gas by 0 and the variable name.
Option | Description | Example |
---|---|---|
string id |
triplet id of contract | 1.11.165 |
uint64_t amount |
amount, doesn't affect anything | 0 |
uint64_t gas |
gas, doesn't affect anything | 0 |
string var_name |
variable name | "var_name" |
string
- result of executing an internal contract call. First 4 bytes(8 characters) - size of output.
void call_contract(string id, string var_name, uint64_t amount, uint64_t gas)
{
contract_object c(id);
string var_1 = c.call(amount, gas, var_name);
string var_2 = c.call(amount, gas, string("var_name"));
}
Member of class contract_object
.
You can call another x86-64 contract. For the call, you will need to pass the amount, count of gas to perform and the call line. If you do not want to limit the call to the gas, 0 is transmitted.
Option | Description | Example |
---|---|---|
string id |
triplet id of contract | 1.11.165 |
uint64_t amount |
amount allocated to the contract, in the smallest units | 0 or 1000000 |
uint64_t gas |
gas restriction for internal call, if you set 0, then there will be no limit | 0 or 10000000 |
string call_line |
call line | greet() or get_balance("1.2.236", "1.3.0") |
string
- result of executing an internal contract call. First 4 bytes(8 characters) - size of output.
string call_contract(string id, string call_line, uint64_t amount, uint64_t gas)
{
contract_object c(id);
return c.call(amount, gas, call_line);
}
Member of class contract_object
.
You can call another x86-64 contract. For the call, you will need to pass the amount, count of gas to perform, callee function name and the call params. If you do not want to limit the call to the gas, 0 is transmitted.
Option | Description | Example |
---|---|---|
string id |
triplet id of contract | 1.11.165 |
uint64_t amount |
amount allocated to the contract, in the smallest units | 0 or 1000000 |
uint64_t int gas |
gas restriction for internal call, if you set 0, then there will be no limit | 0 or 10000000 |
string function_name |
callee function name | get_balance |
args... params |
call params | a, true, 637, string("string_param") |
string
- result of executing an internal contract call. First 4 bytes(8 characters) - size of output.
string call_contract(string id, string var_1, unsigned int var_2, uint64_t amount, uint64_t gas)
{
int var_local = 544;
bool var_bool = true;
contract_object c(id);
return c.call(amount, gas, string("my_function"), var_1, var_2, var_local, var_bool, -45);
}
#include "chain.hpp"
#include "contract_base.hpp"
#include "db_types.hpp"
#include "parameters.hpp"
#include "string.hpp"
namespace x86_64_contract {
class contract : public contract_base
{
public:
void send_to_contract()
{
_value += get_send_value();
}
bool transfer(string to, string asset_id, uint64_t amount)
{
string sender = get_origin_sender();
uint64_t send_with_call = get_send_value();
object sender_obj(sender);
string sender_name = sender_obj.get_property("name");
if (sender != _owner && sender_name != "my_second_account")
{
if (send_with_call < amount)
return false;
else
{
transfer(to, asset_id, amount);
_value += send_with_call - amount;
return true;
}
}
if (_value + send_with_call < amount)
return false;
transfer(to, asset_id, amount);
_value += send_with_call - amount;
return true;
}
void constructor() override
{
_owner = get_origin_sender();
}
private:
string _name { "my_contract" };
DB_STRING(_owner);
DB_UINT64(_value);
};
MAIN(contract, FUNC(send_to_contract) FUNC(transfer))
}