Smart Contracts

The EOS C++ SDK Developer Hub

Welcome to the EOS C++ SDK developer hub. You'll find comprehensive guides and documentation to help you start working with EOS C++ SDK as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Defines API for querying action and sending action.

A EOS.IO action has the following abstract structure:

struct action {
  scope_name scope; // the contract defining the primary code to execute for code/type
  action_name name; // the action to be taken
  permission_level[] authorization; // the accounts and permission levels provided
  bytes data; // opaque data processed by code
};

This API enables your contract to inspect the fields on the current action and act accordingly.

Example:

// Assume this action is used for the following examples:
// {
//  "code": "eos",
//  "type": "transfer",
//  "authorization": [{ "account": "inita", "permission": "active" }],
//  "data": {
//    "from": "inita",
//    "to": "initb",
//    "amount": 1000
//  }
// }

char buffer[128];
uint32_t total = read_action(buffer, 5); // buffer contains the content of the action up to 5 bytes
print(total); // Output: 5

uint32_t msgsize = action_size();
print(msgsize); // Output: size of the above action's data field

require_recipient(N(initc)); // initc account will be notified for this action

require_auth(N(inita)); // Do nothing since inita exists in the auth list
require_auth(N(initb)); // Throws an exception

print(current_time()); // Output: timestamp (in microseconds since 1970) of current block

SUMMARY

Members Descriptions
public uint32_t read_action_data (void * msg,uint32_t len) Copy current action data to the specified location.
public uint32_taction_data_size() Get the length of current action's data field.
public voidrequire_recipient(account_namename) Add the specified account to set of accounts to be notified.
public voidrequire_auth(account_namename) Verify specified account exists in the set of provided auths.
public boolhas_auth(account_namename) Verifies that name has auth.
public voidrequire_auth2(account_namename,permission_namepermission) Verify specified account exists in the set of provided auths.
public boolis_account(account_namename)
public voidsend_inline(char * serialized_action,size_t size) Send an inline action in the context of this action's parent transaction
public voidsend_context_free_inline(char * serialized_action,size_t size) Send an inline context free action in the context of this action's parent transaction
public voidrequire_write_lock(account_namename) Verifies that name exists in the set of write locks held.
public voidrequire_read_lock(account_namename) Verifies that name exists in the set of read locks held.
public uint64_tpublication_time() Get the publication time.
publicaccount_name`[current_receiver](#current_receiver)()` Get the current receiver of the action.
Suggest Edits

read_action_data

Copy current action data to the specified location.

 
uint32_t read_action_data( void* msg, uint32_t len );

Copy up to len bytes of current action data to the specified location

Parameters

  • msg - a pointer where up to len bytes of the current action data will be copied
  • len - len of the current action data to be copied, 0 to report required size

Returns

the number of bytes copied to msg, or number of bytes that can be copied if len==0 passed

Precondition

msg is a valid pointer to a range of memory at least len bytes long

Post Condition

msg is filled with packed action data

Suggest Edits

action_data_size

Get the length of current action's data field.

 
uint32_t action_data_size();

Get the length of the current action's data field. This method is useful for dynamically sized actions

Returns

the length of the current action's data field

require_recipient

Add the specified account to set of accounts to be notified.

Add the specified account to set of accounts to be notified

Parameters

  • name - name of the account to be verified
Suggest Edits

has_auth

Verifies that name has auth.

 

Verifies that name has auth.

Parameters

  • name - name of the account to be verified
Suggest Edits

require_auth

Verify specified account exists in the set of provided auths.

 

Verifies that name exists in the set of provided auths on a action. Throws if not found.

Parameters

  • name - name of the account to be verified
Suggest Edits

require_auth2

Verify specified account exists in the set of provided auths.

 

Verifies that name exists in the set of provided auths on a action. Throws if not found

Parameters

  • name - name of the account to be verified

  • permission - permission level to be verified

Suggest Edits

send_inline

Send an inline action in the context of this action's parent transaction

 

Send an inline action in the context of this action's parent transaction

Parameters

  • serialized_action - serialized action

  • size - size of serialized action in bytes

Precondition

serialized_action is a valid pointer to an array at least size bytes long

Suggest Edits

send_context_free_inline

Send an inline context free action in the context of this action's parent transaction

 

Send an inline context free action in the context of this action's parent transaction

Parameters

  • serialized_action - serialized action

  • size - size of serialized action in bytes

Precondition

serialized_action is a valid pointer to an array at least size bytes long

Suggest Edits

require_write_lock

Verifies that name exists in the set of write locks held.

 

Verifies that name exists in the set of write locks held.

Verifies that name exists in the set of write locks held on a action. Throws if not found

Parameters

  • name - name of the account to be verified
Suggest Edits

require_read_lock

Verifies that name exists in the set of read locks held.

 

Verifies that name exists in the set of read locks held.

Verifies that name exists in the set of read locks held on a action. Throws if not found

Parameters

  • name - name of the account to be verified
Suggest Edits

publication_time

Get the publication time.

 

Returns

the time in microseconds from 1970 of the publication_time

Suggest Edits

current_receiver

Get the current receiver of the action.

 

Get the current receiver of the action

Returns

the account which specifies the current receiver of the action

Suggest Edits

Chain

Defines C API for querying internal chain state.

 

Defines C API for calculating and checking hash.

SUMMARY

Members Descriptions
public uint32_tget_active_producers(account_name* producers,uint32_t datalen) Gets the set of active producers.
Suggest Edits

get_active_producers

Gets the set of active producers.

 

Gets the set of active producers.

Parameters

  • producers - Pointer to a buffer of account names

  • datalen - Byte length of buffer

Returns

uint32_t - Number of bytes actually populated

Precondition

producers is a pointer to a range of memory at least datalen bytes long

Post Condition

the passed in producers pointer gets the array of active producers.

Example:

account_name producers[21];
uint32_t bytes_populated = get_active_producers(producers, sizeof(account_name)*21);
Suggest Edits

Console

Defnes C API to log/print text messages.

 

Defnes C API to log/print text messages.

SUMMARY

Members Descriptions
public voidprints(const char * cstr) Prints string.
public voidprints_l(const char * cstr,uint32_t len) Prints string.
public voidprinti(int64_t value) Prints value as a 64 bit signed integer.
public voidprintui(uint64_t value) Prints value as a 64 bit unsigned integer.
public voidprinti128(const int128_t * value) Prints value as a 128 bit signed integer.
public voidprintui128(const uint128_t * value) Prints value as a 128 bit unsigned integer.
public voidprintsf(float value) Prints value as single-precision floating point number (i.e. float)
public voidprintdf(double value) Prints value as double-precision floating point number (i.e. double)
public voidprintqf(const long double * value) Prints value as quadruple-precision floating point number (i.e. long double)
public voidprintn(uint64_t name) Prints a 64 bit names as base32 encoded string.
public voidprinthex(const void * data,uint32_t datalen)
Suggest Edits

prints

Prints string.

 

Prints string

Parameters

  • cstr - a null terminated string

Example:

prints("Hello World!"); // Output: Hello World!
Suggest Edits

prints_l

Prints string.

 

Prints string up to given length

Parameters

  • cstr - pointer to string

  • len - len of string to be printed

Example:

prints_l("Hello World!", 5); // Output: Hello
Suggest Edits

printi

Prints value as a 64 bit signed integer.

 

Prints value as a 64 bit signed integer

Parameters

  • value of 64 bit signed integer to be printed

Example:

printi(-1e+18); // Output: -1000000000000000000
Suggest Edits

printui

Prints value as a 64 bit unsigned integer.

 

Prints value as a 64 bit unsigned integer

Parameters

  • value of 64 bit unsigned integer to be printed

Example:

printui(1e+18); // Output: 1000000000000000000
Suggest Edits

printi128

Prints value as a 128 bit signed integer.

 

Prints value as a 128 bit signed integer

Parameters

  • value is a pointer to the 128 bit signed integer to be printed

Example:

int128_t large_int(-87654323456);
printi128(&large_int); // Output: -87654323456
Suggest Edits

printui128

Prints value as a 128 bit unsigned integer.

 

Prints value as a 128 bit unsigned integer

Parameters

  • value is a pointer to the 128 bit unsigned integer to be printed

Example:

uint128_t large_int(87654323456);
printui128(&large_int); // Output: 87654323456
Suggest Edits

printsf

Prints value as single-precision floating point number (i.e. float)

 

Prints value as single-precision floating point number

Parameters

  • value of float to be printed

Example:

float value = 5.0 / 10.0;
printsf(value); // Output: 0.5
Suggest Edits

printdf

Prints value as double-precision floating point number (i.e. double)

 

Prints value as double-precision floating point number

Parameters

  • value of double to be printed

Example:

double value = 5.0 / 10.0;
printdf(value); // Output: 0.5
Suggest Edits

printqf

Prints value as quadruple-precision floating point number (i.e. long double)

 

Prints value as quadruple-precision floating point number

Parameters

  • value is a pointer to the long double to be printed

Example:

long double value = 5.0 / 10.0;
printqf(value); // Output: 0.5
Suggest Edits

printn

Prints a 64 bit names as base32 encoded string.

 

Prints a 64 bit names as base32 encoded string

Parameters

  • name - 64 bit name to be printed

Example

printn(N(abcde)); // Output: abcde
Suggest Edits

printhex

Prints a 64 bit names as base32 encoded string

 

Parameters

  • name - Hex name to be printed

Example:

printn(N(abcde)); // Output: abcde
Suggest Edits

Crypto

Defines C API for calculating and checking hash.

 

SUMMARY

Members Descriptions
public voidassert_sha256(char * data,uint32_t length,const checksum256 * hash) Tests if the sha256 hash generated from data matches the provided checksum.
public voidassert_sha1(char * data,uint32_t length,const checksum160 * hash) Tests if the sha1 hash generated from data matches the provided checksum.
public voidassert_sha512(char * data,uint32_t length,const checksum512 * hash) Tests if the sha512 hash generated from data matches the provided checksum.
public voidassert_ripemd160(char * data,uint32_t length,const checksum160 * hash) Tests if the ripemod160 hash generated from data matches the provided checksum.
public voidsha256(char * data,uint32_t length,checksum256 * hash) Hashes data using sha256 and stores result in memory pointed to by hash.
public voidsha1(char * data,uint32_t length,checksum160 * hash) Hashes data using sha1 and stores result in memory pointed to by hash.
public voidsha512(char * data,uint32_t length,checksum512 * hash) Hashes data using sha512 and stores result in memory pointed to by hash.
public voidripemd160(char * data,uint32_t length,checksum160 * hash) Hashes data using ripemod160 and stores result in memory pointed to by hash.
public intrecover_key(const checksum256 * digest,const char * sig,size_t siglen,char * pub,size_t publen) Calculates the public key used for a given signature and hash used to create a message.
public voidassert_recover_key(const checksum256 * digest,const char * sig,size_t siglen,const char * pub,size_t publen) Tests a given public key with the generated key from digest and the signature.
Suggest Edits

assert_sha256

Tests if the sha256 hash generated from data matches the provided checksum.

 

Tests if the sha256 hash generated from data matches the provided checksum. This method is optimized to a NO-OP when in fast evaluation mode.

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - checksum256* hash to compare to

Precondition

assert256 hash of data equals provided hash parameter.

Post Condition

Executes next statement. If was not true, hard return.

Example

checksum hash;
char data;
uint32_t length;
assert_sha256( data, length, hash )
//If the sha256 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("sha256 hash generated from data equals provided hash");
Suggest Edits

assert_sha1

Tests if the sha1 hash generated from data matches the provided checksum.

 

Tests if the sha1 hash generated from data matches the provided checksum. This method is optimized to a NO-OP when in fast evaluation mode.

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - checksum160* hash to compare to

Precondition

sha1 hash of data equals provided hash parameter.

Post Condition

Executes next statement. If was not true, hard return.

Example

checksum hash;
char data;
uint32_t length;
assert_sha1( data, length, hash )
//If the sha1 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("sha1 hash generated from data equals provided hash");
Suggest Edits

assert_sha512

Tests if the sha512 hash generated from data matches the provided checksum.

 

Tests if the sha512 hash generated from data matches the provided checksum. This method is optimized to a NO-OP when in fast evaluation mode.

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - checksum512* hash to compare to

Precondition

assert512 hash of data equals provided hash parameter.

Post Condition

Executes next statement. If was not true, hard return.

Example

checksum hash;
char data;
uint32_t length;
assert_sha512( data, length, hash )
//If the sha512 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("sha512 hash generated from data equals provided hash");
Suggest Edits

assert_ripemd160

Tests if the ripemod160 hash generated from data matches the provided checksum.

 

Tests if the ripemod160 hash generated from data matches the provided checksum.

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - checksum160* hash to compare to

Precondition

assert160 hash of data equals provided hash parameter.

Post Condition

Executes next statement. If was not true, hard return.

Example

checksum hash;
char data;
uint32_t length;
assert_ripemod160( data, length, hash )
//If the ripemod160 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("ripemod160 hash generated from data equals provided hash");
Suggest Edits

sha256

Hashes data using sha256 and stores result in memory pointed to by hash.

 

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - Hash pointer

Example

checksum calc_hash;
sha256( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Suggest Edits

sha1

Hashes data using sha1 and stores result in memory pointed to by hash.

 

Hashes data using sha1 and stores result in memory pointed to by hash.

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - Hash pointer

Example

checksum calc_hash;
sha1( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Suggest Edits

sha512

Hashes data using sha512 and stores result in memory pointed to by hash.

 

Hashes data using sha512 and stores result in memory pointed to by hash.

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - Hash pointer

Example

checksum calc_hash;
sha512( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Suggest Edits

ripemd160

Hashes data using ripemod160 and stores result in memory pointed to by hash.

 

Parameters

  • data - Data you want to hash

  • length - Data length

  • hash - Hash pointer

Example

checksum calc_hash;
ripemod160( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Suggest Edits

recover_key

Calculates the public key used for a given signature and hash used to create a message.

 

Parameters

  • digest - Hash used to create a message
  • sig - Signature
  • siglen - Signature length
  • pub - Public key
  • publen - Public key length

Example


Suggest Edits

assert_recover_key

Tests a given public key with the generated key from digest and the signature.

 

Parameters

  • digest - What the key will be generated from

  • sig - Signature

  • siglen - Signature length

  • pub - Public key

  • publen - Public key length

Precondition

assert recovery key of pub equals the key generated from the digest parameter

Post Condition

Executes next statement. If was not true, hard return.

Example

checksum digest;
char sig;
size_t siglen;
char pub;
size_t publen;
assert_recover_key( digest, sig, siglen, pub, publen )
// If the given public key does not match with the generated key from digest and the signature, anything below will never fire.
eosio::print("pub key matches the pub key generated from digest");
Suggest Edits

Database

Defines C APIs for interfacing with the database.

 

Supported Table TypesFollowing are the table types supported by the C API:* Primary Table

  • 64-bit integer key
  • Secondary Index Table
  • 64-bit integer key
  • 128-bit integer key
  • 256-bit integer key
  • double key
  • long double

SUMMARY

Members Descriptions
public int32_tdb_store_i64(account_namescope,table_nametable,account_namepayer,uint64_t id,const void * data,uint32_t len) Store a record in a primary 64-bit integer index table.
public voiddb_update_i64(int32_t iterator,account_namepayer,const void * data,uint32_t len) Update a record inside a primary 64-bit integer index table.
public voiddb_remove_i64(int32_t iterator) Remove a record inside a primary 64-bit integer index table.
public int32_tdb_get_i64(int32_t iterator,const void * data,uint32_t len) Get a record inside a primary 64-bit integer index table.
public int32_tdb_next_i64(int32_t iterator,uint64_t * primary) Get the next record after the given iterator from a primary 64-bit integer index table.
public int32_tdb_previous_i64(int32_t iterator,uint64_t * primary) Get the previous record before the given iterator from a primary 64-bit integer index table.
public int32_tdb_find_i64(account_namecode,account_namescope,table_nametable,uint64_t id) Find a record inside a primary 64-bit integer index table.
public int32_tdb_lowerbound_i64(account_namecode,account_namescope,table_nametable,uint64_t id) Find the lowerbound record given a key inside a primary 64-bit integer index table.
public int32_tdb_upperbound_i64(account_namecode,account_namescope,table_nametable,uint64_t id) Find the upperbound record given a key inside a primary 64-bit integer index table.
public int32_tdb_end_i64(account_namecode,account_namescope,table_nametable) Find the latest record inside a primary 64-bit integer index table.
public int32_tdb_idx64_store(account_namescope,table_nametable,account_namepayer,uint64_t id,const uint64_t * secondary) Store a record's secondary index in a secondary 64-bit integer index table.
public voiddb_idx64_update(int32_t iterator,account_namepayer,const uint64_t * secondary) Update a record's secondary index inside a secondary 64-bit integer index table.
public voiddb_idx64_remove(int32_t iterator) Remove a record's secondary index from a secondary 64-bit integer index table.
public int32_tdb_idx64_next(int32_t iterator,uint64_t * primary) Get the next secondary index inside a secondary 64-bit integer index table.
public int32_tdb_idx64_previous(int32_t iterator,uint64_t * primary) Get the previous secondary index inside a secondary 64-bit integer index table.
public int32_tdb_idx64_find_primary(account_namecode,account_namescope,table_nametable,uint64_t * secondary,uint64_t primary) Get the secondary index of a record from a secondary 64-bit integer index table given the record's primary key.
public int32_tdb_idx64_find_secondary(account_namecode,account_namescope,table_nametable,const uint64_t * secondary,uint64_t * primary) Get the secondary index of a record from a secondary 64-bit integer index table given the secondary index key.
public int32_tdb_idx64_lowerbound(account_namecode,account_namescope,table_nametable,uint64_t * secondary,uint64_t * primary) Get the secondary index of a record from a secondary 64-bit integer index table given the secondary index key.
public int32_tdb_idx64_upperbound(account_namecode,account_namescope,table_nametable,uint64_t * secondary,uint64_t * primary) Get the secondary index of a record from a secondary 64-bit integer index table given the secondary index key.
public int32_tdb_idx64_end(account_namecode,account_namescope,table_nametable) Get the last secondary index from a secondary 64-bit integer index table.
public int32_tdb_idx128_store(account_namescope,table_nametable,account_namepayer,uint64_t id,const uint128_t * secondary) Store a record's secondary index in a secondary 128-bit integer index table.
public voiddb_idx128_update(int32_t iterator,account_namepayer,const uint128_t * secondary) Update a record's secondary index inside a secondary 128-bit integer index table.
public voiddb_idx128_remove(int32_t iterator) Remove a record's secondary index from a secondary 128-bit integer index table.
public int32_tdb_idx128_next(int32_t iterator,uint64_t * primary) Get the next secondary index inside a secondary 128-bit integer index table.
public int32_tdb_idx128_previous(int32_t iterator,uint64_t * primary) Get the previous secondary index inside a secondary 128-bit integer index table.
public int32_tdb_idx128_find_primary(account_namecode,account_namescope,table_nametable,uint128_t * secondary,uint64_t primary) Get the secondary index of a record from a secondary 128-bit integer index table given the record's primary key.
public int32_tdb_idx128_find_secondary(account_namecode,account_namescope,table_nametable,const uint128_t * secondary,uint64_t * primary) Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key.
public int32_tdb_idx128_lowerbound(account_namecode,account_namescope,table_nametable,uint128_t * secondary,uint64_t * primary) Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key.
public int32_tdb_idx128_upperbound(account_namecode,account_namescope,table_nametable,uint128_t * secondary,uint64_t * primary) Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key.
public int32_tdb_idx128_end(account_namecode,account_namescope,table_nametable) Get the last secondary index from a secondary 128-bit integer index table.
public int32_tdb_idx256_store(account_namescope,table_nametable,account_namepayer,uint64_t id,const void * data,uint32_t data_len) Store a record's secondary index in a secondary 256-bit integer index table.
public voiddb_idx256_update(int32_t iterator,account_namepayer,const void * data,uint32_t data_len) Update a record's secondary index inside a secondary 256-bit integer index table.
public voiddb_idx256_remove(int32_t iterator) Remove a record's secondary index from a secondary 256-bit integer index table.
public int32_tdb_idx256_next(int32_t iterator,uint64_t * primary) Get the next secondary index inside a secondary 256-bit integer index table.
public int32_tdb_idx256_previous(int32_t iterator,uint64_t * primary) Get the previous secondary index inside a secondary 256-bit integer index table.
public int32_tdb_idx256_find_primary(account_namecode,account_namescope,table_nametable,void * data,uint32_t data_len,uint64_t primary) Get the secondary index of a record from a secondary 256-bit integer index table given the record's primary key.
public int32_tdb_idx256_find_secondary(account_namecode,account_namescope,table_nametable,const void * data,uint32_t data_len,uint64_t * primary) Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key.
public int32_tdb_idx256_lowerbound(account_namecode,account_namescope,table_nametable,void * data,uint32_t data_len,uint64_t * primary) Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key.
public int32_tdb_idx256_upperbound(account_namecode,account_namescope,table_nametable,void * data,uint32_t data_len,uint64_t * primary) Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key.
public int32_tdb_idx256_end(account_namecode,account_namescope,table_nametable) Get the last secondary index from a secondary 256-bit integer index table.
public int32_tdb_idx_double_store(account_namescope,table_nametable,account_namepayer,uint64_t id,const double * secondary) Store a record's secondary index in a secondary double index table.
public voiddb_idx_double_update(int32_t iterator,account_namepayer,const double * secondary) Update a record's secondary index inside a secondary double index table.
public voiddb_idx_double_remove(int32_t iterator) Remove a record's secondary index from a secondary double index table.
public int32_tdb_idx_double_next(int32_t iterator,uint64_t * primary) Get the next secondary index inside a secondary double index table.
public int32_tdb_idx_double_previous(int32_t iterator,uint64_t * primary) Get the previous secondary index inside a secondary double index table.
public int32_tdb_idx_double_find_primary(account_namecode,account_namescope,table_nametable,double * secondary,uint64_t primary) Get the secondary index of a record from a secondary double index table given the record's primary key.
public int32_tdb_idx_double_find_secondary(account_namecode,account_namescope,table_nametable,const double * secondary,uint64_t * primary) Get the secondary index of a record from a secondary double index table given the secondary index key.
public int32_tdb_idx_double_lowerbound(account_namecode,account_namescope,table_nametable,double * secondary,uint64_t * primary) Get the secondary index of a record from a secondary double index table given the secondary index key.
public int32_tdb_idx_double_upperbound(account_namecode,account_namescope,table_nametable,double * secondary,uint64_t * primary) Get the secondary index of a record from a secondary double index table given the secondary index key.
public int32_tdb_idx_double_end(account_namecode,account_namescope,table_nametable) Get the last secondary index from a secondary double index table.
public int32_tdb_idx_long_double_store(account_namescope,table_nametable,account_namepayer,uint64_t id,const long double * secondary) Store a record's secondary index in a secondary long double index table.
public voiddb_idx_long_double_update(int32_t iterator,account_namepayer,const long double * secondary) Update a record's secondary index inside a secondary long double index table.
public voiddb_idx_long_double_remove(int32_t iterator) Remove a record's secondary index from a secondary long double index table.
public int32_tdb_idx_long_double_next(int32_t iterator,uint64_t * primary) Get the next secondary index inside a secondary long double index table.
public int32_tdb_idx_long_double_previous(int32_t iterator,uint64_t * primary) Get the previous secondary index inside a secondary long double index table.
public int32_tdb_idx_long_double_find_primary(account_namecode,account_namescope,table_nametable,long double * secondary,uint64_t primary) Get the secondary index of a record from a secondary long double index table given the record's primary key.
public int32_tdb_idx_long_double_find_secondary(account_namecode,account_namescope,table_nametable,const long double * secondary,uint64_t * primary) Get the secondary index of a record from a secondary long double index table given the secondary index key.
public int32_tdb_idx_long_double_lowerbound(account_namecode,account_namescope,table_nametable,long double * secondary,uint64_t * primary) Get the secondary index of a record from a secondary long double index table given the secondary index key.
public int32_tdb_idx_long_double_upperbound(account_namecode,account_namescope,table_nametable,long double * secondary,uint64_t * primary) Get the secondary index of a record from a secondary long double index table given the secondary index key.
public int32_tdb_idx_long_double_end(account_namecode,account_namescope,table_nametable) Get the last secondary index from a secondary long double index table.
Suggest Edits

db_store_i64

Store a record in a primary 64-bit integer index table

 

Parameters

  • scope - The scope where the record will be stored

  • table - The ID/name of the table within the current scope/code context

  • payer - The account that is paying for this storage

  • id - Id of the entry

  • data - Record to store

  • len - Size of data

Precondition

len >= sizeof(data)

Precondition

data is a valid pointer to a range of memory at least len bytes long

Precondition

*((uint64_t*)data) stores the primary key

Precondition

this method is being called from an apply context (not validate or precondition)

Returns

iterator to the newly created object

Post Condition

a new entry is created in the table

Suggest Edits

db_update_i64

Update a record inside a primary 64-bit integer index table.

 

Update a record inside a primary 64-bit integer index table

Parameters

  • iterator - Iterator of the record to update

  • payer - The account that is paying for this storage

  • data - New updated record

  • len - Size of data

Precondition

len >= sizeof(data)

Precondition

data is a valid pointer to a range of memory at least len bytes long

Precondition

*((uint64_t*)data) stores the primary key

Precondition

this method is being called from an apply context (not validate or precondition)

Precondition

iterator is pointing to the existing data inside the table

Post Condition

the data pointed by the iterator is replaced with the new data

Suggest Edits

db_remove_i64

Remove a record inside a primary 64-bit integer index table.

 

Remove a record inside a primary 64-bit integer index table

Parameters

  • iterator - The iterator pointing to the record to remove

Precondition

iterator is pointing to the existing data inside the table

Post Condition

the data is removed

Example:

int itr = db_find_i64(receiver, receiver, table1, N(alice));
eosio_assert(itr >= 0, "primary_i64_general - db_find_i64");
db_remove_i64(itr);
itr = db_find_i64(receiver, receiver, table1, N(alice));
Suggest Edits

db_get_i64

Get a record inside a primary 64-bit integer index table.

 

Get a record inside a primary 64-bit integer index table

Parameters

  • iterator - The iterator to the record
  • data - The buffer which will be replaced with the retrieved record
  • len - Size of the buffer

Returns

size of the retrieved record

Precondition

iterator is pointing to the existing data inside the table

Precondition

data is a valid pointer to a range of memory at least len bytes long

Precondition

len needs to be larger than the size of the data that is going to be retrieved

Post Condition

data will be filled with the retrieved data

Example:

char value[50];
auto len = db_get_i64(itr, value, buffer_len);
value[len] = '\0';
std::string s(value);
Suggest Edits

db_next_i64

Get the next record after the given iterator from a primary 64-bit integer index table.

 

Get the next record after the given iterator from a primary 64-bit integer index table

Parameters

  • iterator - The iterator to the record
  • primary - It will be replaced with the primary key of the next record

Returns

iterator to the next record

Precondition

iterator is pointing to the existing data inside the table

Post Condition

primary will be replaced with the primary key of the data proceeding the data pointed by the iterator

Example:

int charlie_itr = db_find_i64(receiver, receiver, table1, N(charlie));
// nothing after charlie
uint64_t prim = 0
int end_itr = db_next_i64(charlie_itr, &prim);
Suggest Edits

db_previous_i64

Get the previous record before the given iterator from a primary 64-bit integer index table.

 

Get the previous record before the given iterator from a primary 64-bit integer index table

Parameters

  • iterator - The iterator to the record
  • primary - It will be replaced with the primary key of the previous record

Returns

iterator to the previous record

Precondition

iterator is pointing to the existing data inside the table

Post Condition

primary will be replaced with the primary key of the data preceeding the data pointed by the iterator

Example:

uint64_t prim = 123;
int itr_prev = db_previous_i64(itr, &prim);
Suggest Edits

db_find_i64

Find a record inside a primary 64-bit integer index table.

 

Find a record inside a primary 64-bit integer index table

Parameters

  • scope - The scope where the record is stored
  • table - The table name where the record is stored
  • id - The primary key of the record to look up

Returns

iterator to the found record

Example

int itr = db_find_i64(receiver, receiver, table1, N(charlie));
Suggest Edits

db_lowerbound_i64

Find the lowerbound record given a key inside a primary 64-bit integer index table.

 

Find the lowerbound record given a key inside a primary 64-bit integer index table Lowerbound record is the first nearest record which primary key is <= the given key

Parameters

  • code - The name of the owner of the table
  • scope - The scope where the table resides
  • table - The table name
  • id - The primary key used as a pivot to determine the lowerbound record

Returns

iterator to the lowerbound record

Suggest Edits

db_upperbound_i64

Find the upperbound record given a key inside a primary 64-bit integer index table.

 

Find the upperbound record given a key inside a primary 64-bit integer index table Upperbound record is the first nearest record which primary key is < the given key

Parameters

  • code - The name of the owner of the table
  • scope - The scope where the table resides
  • table - The table name
  • id - The primary key used as a pivot to determine the upperbound record

Returns

iterator to the upperbound record

Suggest Edits

db_end_i64

Find the latest record inside a primary 64-bit integer index table.

 

Find the latest record inside a primary 64-bit integer index table

Parameters

  • code - The name of the owner of the table
  • scope - The scope where the table resides
  • table - The table name

Returns

iterator to the last record

Suggest Edits

db_idx64_store

Store a record's secondary index in a secondary 64-bit integer index table.

 

Parameters

  • scope - The scope where the secondary index will be stored
  • table - The table name where the secondary index will be stored
  • payer - The account that is paying for this storage
  • id - The primary key of the record which secondary index to be stored
  • secondary - The pointer to the key of the secondary index to store

Returns

iterator to the newly created secondary index

Post Condition

new secondary index is created

Suggest Edits

db_idx64_update

Update a record's secondary index inside a secondary 64-bit integer index table.

 

Update a record's secondary index inside a secondary 64-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • payer - The account that is paying for this storage
  • secondary - The pointer to the new key of the secondary index

Precondition

iterator is pointing to existing secondary index

Post Condition

the seconday index pointed by the iterator is updated by the new value

Suggest Edits

db_idx64_remove

Remove a record's secondary index from a secondary 64-bit integer index table.

 

Remove a record's secondary index from a secondary 64-bit integer index table

Parameters

  • iterator - The iterator to the secondary index to be removed

Precondition

iterator is pointing to existing secondary index

Post Condition

the secondary index pointed by the iterator is removed from the table

Suggest Edits

db_idx64_next

Get the next secondary index inside a secondary 64-bit integer index table.

 

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the next secondary index

Returns

iterator to the next secondary index

Precondition

iterator is pointing to the existing secondary index inside the table

Post Condition

primary will be replaced with the primary key of the secondary index proceeding the secondary index pointed by the iterator

Suggest Edits

db_idx64_previous

Get the previous secondary index inside a secondary 64-bit integer index table.

 

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the previous secondary index

Returns

iterator to the previous secondary index

Precondition

iterator is pointing to the existing secondary index inside the table

Post Condition

primary will be replaced with the primary key of the secondary index preceeding the secondary index pointed by the iterator

Suggest Edits

db_idx64_find_primary

Get the secondary index of a record from a secondary 64-bit integer index table given the record's primary key.

 

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - It will be replaced with the secondary index key
  • primary - The record's primary key

Precondition

A correponding primary 64-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given record's primary key

Suggest Edits

db_idx64_find_secondary

Get the secondary index of a record from a secondary 64-bit integer index table given the secondary index key.

 

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key
  • primary - It will be replaced with the primary key of the record which the secondary index contains

Precondition

A correponding primary 64-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given secondary index key

Suggest Edits

db_idx64_lowerbound

Get the secondary index of a record from a secondary 64-bit integer index table given the secondary index key.

 

Get the lowerbound secondary index from a secondary 64-bit integer index table given the secondary index key Lowerbound secondary index is the first secondary index which key is <= the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key which acts as lowerbound pivot point, later on it will be replaced with the lowerbound secondary index key
  • primary - It will be replaced with the primary key of the record which the lowerbound secondary index contains

Precondition

A correponding primary 64-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the lowerbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the lowerbound secondary index

Returns

iterator to the lowerbound secondary index

Suggest Edits

db_idx64_upperbound

Get the secondary index of a record from a secondary 64-bit integer index table given the secondary index key.

 

Get the upperbound secondary index from a secondary 64-bit integer index table given the secondary index key Upperbound secondary index is the first secondary index which key is < the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key which acts as upperbound pivot point, later on it will be replaced with the upperbound secondary index key
  • primary - It will be replaced with the primary key of the record which the upperbound secondary index contains

Precondition

A correponding primary 64-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the upperbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the upperbound secondary index

Returns

iterator to the upperbound secondary index

Suggest Edits

db_idx64_end

Get the last secondary index from a secondary 64-bit integer index table.

 

Get the last secondary index from a secondary 64-bit integer index table

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides

Returns

iterator to the last secondary index

Suggest Edits

db_idx128_store

Store a record's secondary index in a secondary 128-bit integer index table.

 

Store a record's secondary index in a secondary 128-bit integer index table

Parameters

  • scope - The scope where the secondary index will be stored
  • table - The table name where the secondary index will be stored
  • payer - The account that is paying for this storage
  • id - The primary key of the record which secondary index to be stored
  • secondary - The pointer to the key of the secondary index to store

Returns

iterator to the newly created secondary index

Post Condition

new secondary index is created

Suggest Edits

db_idx128_update

Update a record's secondary index inside a secondary 128-bit integer index table.

 

Update a record's secondary index inside a secondary 128-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • payer - The account that is paying for this storage
  • secondary - The pointer to the new key of the secondary index

Precondition

iterator is pointing to existing secondary index

Post Condition

the seconday index pointed by the iterator is updated by the new value

Suggest Edits

db_idx128_remove

Remove a record's secondary index from a secondary 128-bit integer index table.

 

Remove a record's secondary index from a secondary 128-bit integer index table

Parameters

  • iterator - The iterator to the secondary index to be removed

Precondition

iterator is pointing to existing secondary index

Post Condition

the secondary index pointed by the iterator is removed from the table

Suggest Edits

db_idx128_next

Get the next secondary index inside a secondary 128-bit integer index table.

 

Get the next secondary index inside a secondary 128-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the next secondary index

Returns

iterator to the next secondary index

Precondition

iterator is pointing to the existing secondary index inside the table

Post Condition

primary will be replaced with the primary key of the secondary index proceeding the secondary index pointed by the iterator

Suggest Edits

db_idx128_previous

Get the previous secondary index inside a secondary 128-bit integer index table.

 

Get the previous secondary index inside a secondary 128-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the previous secondary index

Returns

iterator to the previous secondary index

Precondition

iterator is pointing to the existing secondary index inside the table

Post Condition

primary will be replaced with the primary key of the secondary index preceeding the secondary index pointed by the iterator

Suggest Edits

db_idx128_find_primary

Get the secondary index of a record from a secondary 128-bit integer index table given the record's primary key.

 

Get the secondary index of a record from a secondary 128-bit integer index table given the record's primary key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - It will be replaced with the secondary index key
  • primary - The record's primary key

Precondition

A correponding primary 128-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given record's primary key

Suggest Edits

db_idx128_find_secondary

Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key.

 

Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key

  • primary - It will be replaced with the primary key of the record which the secondary index contains

Precondition

A correponding primary 128-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given secondary index key

Suggest Edits

db_idx128_lowerbound

Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key.

 

Get the lowerbound secondary index from a secondary 128-bit integer index table given the secondary index key Lowerbound secondary index is the first secondary index which key is <= the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key which acts as lowerbound pivot point, later on it will be replaced with the lowerbound secondary index key
  • primary - It will be replaced with the primary key of the record which the lowerbound secondary index contains

Precondition

A correponding primary 128-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the lowerbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the lowerbound secondary index

Returns

iterator to the lowerbound secondary index

Suggest Edits

db_idx128_upperbound

Get the secondary index of a record from a secondary 128-bit integer index table given the secondary index key.

 

Get the upperbound secondary index from a secondary 128-bit integer index table given the secondary index key Upperbound secondary index is the first secondary index which key is < the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key which acts as upperbound pivot point, later on it will be replaced with the upperbound secondary index key
  • primary - It will be replaced with the primary key of the record which the upperbound secondary index contains

Precondition

A correponding primary 128-bit integer index table with the given code, scope table must exist

Post Condition

The secondary param will contains the upperbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the upperbound secondary index

Returns

iterator to the upperbound secondary index

Suggest Edits

db_idx128_end

Get the last secondary index from a secondary 128-bit integer index table.

 

Get the last secondary index from a secondary 128-bit integer index table

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

Returns

iterator to the last secondary index

Suggest Edits

db_idx256_store

Store a record's secondary index in a secondary 256-bit integer index table.

 

Store a record's secondary index in a secondary 256-bit integer index table

Parameters

  • scope - The scope where the secondary index will be stored
  • table - The table name where the secondary index will be stored
  • payer - The account that is paying for this storage
  • id - The primary key of the record which secondary index to be stored
  • data - The pointer to the key of the secondary index to store
  • data_len - Size of the key of the secondary index to store

Returns

iterator to the newly created secondary index

Precondition

data is pointing to range of memory at least data_len bytes long

Post Condition

new secondary index is created

Suggest Edits

db_idx256_update

Update a record's secondary index inside a secondary 256-bit integer index table.

 

Update a record's secondary index inside a secondary 256-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • payer - The account that is paying for this storage
  • data - The pointer to the new key of the secondary index
  • data_len - Size of the new key of the secondary index to store

Precondition

iterator is pointing to existing secondary index

Post Condition

the seconday index pointed by the iterator is updated by the new value

Suggest Edits

db_idx256_remove

Remove a record's secondary index from a secondary 256-bit integer index table.

 

Remove a record's secondary index from a secondary 256-bit integer index table

Parameters

  • iterator - The iterator to the secondary index to be removed

Precondition

iterator is pointing to existing secondary index

Post Condition

the secondary index pointed by the iterator is removed from the table

Suggest Edits

db_idx256_next

Get the next secondary index inside a secondary 256-bit integer index table.

 

Get the next secondary index inside a secondary 256-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the next secondary index

Returns

iterator to the next secondary index

Precondition

iterator is pointing to the existing secondary index inside the table

Post Condition

primary will be replaced with the primary key of the secondary index proceeding the secondary index pointed by the iterator

Suggest Edits

db_idx256_previous

Get the previous secondary index inside a secondary 256-bit integer index table.

 

Get the previous secondary index inside a secondary 256-bit integer index table

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the previous secondary index

Returns

iterator to the previous secondary index

Precondition

iterator is pointing to the existing secondary index inside the table

Post Condition

primary will be replaced with the primary key of the secondary index preceeding the secondary index pointed by the iterator

Suggest Edits

db_idx256_find_primary

Get the secondary index of a record from a secondary 256-bit integer index table given the record's primary key.

 

Get the secondary index of a record from a secondary 256-bit integer index table given the record's primary key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • data - The buffer which will be replaced with the secondary index key
  • data_len - The buffer size
  • primary - The record's primary key

Precondition

A correponding primary 256-bit integer index table with the given code, scope table must exist

Post Condition

The data param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given record's primary key

Suggest Edits

db_idx256_find_secondary

Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key.

 

Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • data - The pointer to the secondary index key
  • data_len - Size of the secondary index key
  • primary - It will be replaced with the primary key of the record which the secondary index contains

Precondition

A correponding primary 256-bit integer index table with the given code, scope table must exist

Post Condition

The data param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given secondary index key

Suggest Edits

db_idx256_lowerbound

Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key.

 

Get the lowerbound secondary index from a secondary 256-bit integer index table given the secondary index key Lowerbound secondary index is the first secondary index which key is <= the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • data - The pointer to the secondary index key which acts as lowerbound pivot point, later on it will be replaced with the lowerbound secondary index key
  • data_len - Size of the secondary index key
  • primary - It will be replaced with the primary key of the record which the lowerbound secondary index contains

Precondition

A correponding primary 256-bit integer index table with the given code, scope table must exist

Post Condition

The data param will contains the lowerbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the lowerbound secondary index

Returns

iterator to the lowerbound secondary index

Suggest Edits

db_idx256_upperbound

Get the secondary index of a record from a secondary 256-bit integer index table given the secondary index key.

 

Get the upperbound secondary index from a secondary 256-bit integer index table given the secondary index key Upperbound secondary index is the first secondary index which key is < the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • data - The pointer to the secondary index key which acts as lowerbound pivot point, later on it will be replaced with the lowerbound secondary index key
  • data_len - Size of the secondary index key
  • primary - It will be replaced with the primary key of the record which the upperbound secondary index contains

Precondition

A correponding primary 256-bit integer index table with the given code, scope table must exist

Post Condition

The data param will contains the upperbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the upperbound secondary index

Returns

iterator to the upperbound secondary index

Suggest Edits

db_idx256_end

Get the last secondary index from a secondary 256-bit integer index table.

 

Get the last secondary index from a secondary 256-bit integer index table

Parameters

  • code - The owner of the secondary index table

  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

Returns

iterator to the last secondary index

db_idx_double_store

Store a record's secondary index in a secondary double index table.

Store a record's secondary index in a secondary double index table

Parameters

  • scope - The scope where the secondary index will be stored

  • table - The table name where the secondary index will be stored

  • payer - The account that is paying for this storage

  • id - The primary key of the record which secondary index to be stored

  • secondary - The pointer to the key of the secondary index to store

Returns

iterator to the newly created secondary index

Suggest Edits

db_idx_double_update

Update a record's secondary index inside a secondary double index table.

 

Update a record's secondary index inside a secondary double index table

Parameters

  • iterator - The iterator to the secondary index
  • payer - The account that is paying for this storage

  • secondary - The pointer to the new key of the secondary index

db_idx_double_remove

Remove a record's secondary index from a secondary double index table.

Remove a record's secondary index from a secondary double index table

Parameters

  • iterator - The iterator to the secondary index to be removed
Suggest Edits

db_idx_double_next

Get the next secondary index inside a secondary double index table.

 

Get the next secondary index inside a secondary double index table

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the next secondary index

Returns

iterator to the next secondary index

Suggest Edits

db_idx_double_previous

Get the previous secondary index inside a secondary double index table.

 

Get the previous secondary index inside a secondary double index table

Parameters

  • iterator - The iterator to the secondary index
  • primary - It will be replaced with the primary key of the record which is stored in the previous secondary index

Returns

iterator to the previous secondary index

Suggest Edits

db_idx_double_find_primary

Get the secondary index of a record from a secondary double index table given the record's primary key.

 

Get the secondary index of a record from a secondary double index table given the record's primary key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - It will be replaced with the secondary index key

  • primary - The record's primary key

Precondition

A correponding primary double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given record's primary key

Suggest Edits

db_idx_double_find_secondary

Get the secondary index of a record from a secondary double index table given the secondary index key.

 

Get the secondary index of a record from a secondary double index table given the secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key
  • primary - It will be replaced with the primary key of the record which the secondary index contains

Precondition

A correponding primary double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given secondary index key

Suggest Edits

db_idx_double_lowerbound

Get the secondary index of a record from a secondary double index table given the secondary index key.

 

Get the lowerbound secondary index from a secondary double index table given the secondary index key Lowerbound secondary index is the first secondary index which key is <= the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key which acts as lowerbound pivot point, later on it will be replaced with the lowerbound secondary index key
  • primary - It will be replaced with the primary key of the record which the lowerbound secondary index contains

Precondition

A correponding primary double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the lowerbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the lowerbound secondary index

Returns

iterator to the lowerbound secondary index

Suggest Edits

db_idx_double_upperbound

Get the secondary index of a record from a secondary double index table given the secondary index key.

 

Get the upperbound secondary index from a secondary double index table given the secondary index key Upperbound secondary index is the first secondary index which key is < the given secondary index key

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides
  • table - The table where the secondary index resides
  • secondary - The pointer to the secondary index key which acts as upperbound pivot point, later on it will be replaced with the upperbound secondary index key
  • primary - It will be replaced with the primary key of the record which the upperbound secondary index contains

Precondition

A correponding primary double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the upperbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the upperbound secondary index

Returns

iterator to the upperbound secondary index

Suggest Edits

db_idx_double_end

Get the last secondary index from a secondary double index table.

 

Get the last secondary index from a secondary double index table

Parameters

  • code - The owner of the secondary index table
  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

Returns

iterator to the last secondary index

db_idx_long_double_store

Store a record's secondary index in a secondary long double index table.

Store a record's secondary index in a secondary long double index table

Parameters

  • scope - The scope where the secondary index will be stored

  • table - The table name where the secondary index will be stored

  • payer - The account that is paying for this storage

  • id - The primary key of the record which secondary index to be stored

  • secondary - The pointer to the key of the secondary index to store

Returns

iterator to the newly created secondary index

Suggest Edits

db_idx_long_double_update

Update a record's secondary index inside a secondary long double index table.

 

Update a record's secondary index inside a secondary long double index table

Parameters

  • iterator - The iterator to the secondary index
  • payer - The account that is paying for this storage
  • secondary - The pointer to the new key of the secondary index
Suggest Edits

db_idx_long_double_remove

Remove a record's secondary index from a secondary long double index table.

 

Remove a record's secondary index from a secondary long double index table

Parameters

  • iterator - The iterator to the secondary index to be removed
Suggest Edits

db_idx_long_double_next

Get the next secondary index inside a secondary long double index table.

 

Get the next secondary index inside a secondary long double index table

Parameters

  • iterator - The iterator to the secondary index

  • primary - It will be replaced with the primary key of the record which is stored in the next secondary index

Returns

iterator to the next secondary index

Suggest Edits

db_idx_long_double_previous

Get the previous secondary index inside a secondary long double index table.

 

Get the previous secondary index inside a secondary long double index table

Parameters

  • iterator - The iterator to the secondary index

  • primary - It will be replaced with the primary key of the record which is stored in the previous secondary index

Returns

iterator to the previous secondary index

Suggest Edits

db_idx_long_double_find_primary

Get the secondary index of a record from a secondary long double index table given the record's primary key.

 

Get the secondary index of a record from a secondary long double index table given the record's primary key

Parameters

  • code - The owner of the secondary index table

  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

  • secondary - It will be replaced with the secondary index key

  • primary - The record's primary key

Precondition

A correponding primary long double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given record's primary key

Suggest Edits

db_idx_long_double_find_secondary

Get the secondary index of a record from a secondary long double index table given the secondary index key.

 

Get the secondary index of a record from a secondary long double index table given the secondary index key

Parameters

  • code - The owner of the secondary index table

  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

  • secondary - The pointer to the secondary index key

  • primary - It will be replaced with the primary key of the record which the secondary index contains

Precondition

A correponding primary long double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the appropriate secondary index key

Post Condition

The primary param will contains the record that corresponds to the appropriate secondary index

Returns

iterator to the secondary index which contains the given secondary index key

Suggest Edits

db_idx_long_double_lowerbound

Get the secondary index of a record from a secondary long double index table given the secondary index key.

 

Get the lowerbound secondary index from a secondary long double index table given the secondary index key Lowerbound secondary index is the first secondary index which key is <= the given secondary index key

Parameters

  • code - The owner of the secondary index table

  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

  • secondary - The pointer to the secondary index key which acts as lowerbound pivot point, later on it will be replaced with the lowerbound secondary index key

  • primary - It will be replaced with the primary key of the record which the lowerbound secondary index contains

Precondition

A correponding primary long double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the lowerbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the lowerbound secondary index

Returns

iterator to the lowerbound secondary index

Suggest Edits

db_idx_long_double_upperbound

Get the secondary index of a record from a secondary long double index table given the secondary index key.

 

Get the upperbound secondary index from a secondary long double index table given the secondary index key Upperbound secondary index is the first secondary index which key is < the given secondary index key

Parameters

  • code - The owner of the secondary index table

  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

  • secondary - The pointer to the secondary index key which acts as upperbound pivot point, later on it will be replaced with the upperbound secondary index key

  • primary - It will be replaced with the primary key of the record which the upperbound secondary index contains

Precondition

A correponding primary long double index table with the given code, scope table must exist

Post Condition

The secondary param will contains the upperbound secondary index key

Post Condition

The primary param will contains the record that corresponds to the upperbound secondary index

Returns

iterator to the upperbound secondary index

Suggest Edits

db_idx_long_double_end

Get the last secondary index from a secondary long double index table.

 

Get the last secondary index from a secondary long double index table

Parameters

  • code - The owner of the secondary index table

  • scope - The scope where the secondary index resides

  • table - The table where the secondary index resides

Returns

iterator to the last secondary index

Suggest Edits

System

Defines API for interacting with system level intrinsics.

 

SUMMARY

Members Descriptions
public voideosio_assert(uint32_t test,const char * msg) Aborts processing of this action and unwinds all pending changes.
public voideosio_assert_message(uint32_t test,const char * msg,uint32_t msg_len) Aborts processing of this action and unwinds all pending changes.
public voideosio_assert_code(uint32_t test,uint64_t code) Aborts processing of this action and unwinds all pending changes.
public voideosio_exit(int32_t code) Aborts execution of wasm without failing the contract.
public uint64_tcurrent_time() Get time of the last accepted block.
public uint32_tnow() Get time (rounded down to the nearest second) of the current block (i.e. the block including this action)
Suggest Edits

eosio_assert

Aborts processing of this action and unwinds all pending changes.

 

Aborts processing of this action and unwinds all pending changes if the test condition is true

Parameters

  • test - 0 to abort, 1 to ignore

Example:

eosio_assert(1 == 2, "One is equal to two.");
eosio_assert(1 != 1, "One is not equal to one.");
Suggest Edits

eosio_assert_message

Aborts processing of this action and unwinds all pending changes.

 

Aborts processing of this action and unwinds all pending changes if the test condition is true

Parameters

  • test - 0 to abort, 1 to ignore

  • msg - a pointer to the start of string explaining the reason for failure

  • msg_len - length of the string

Suggest Edits

eosio_assert_code

Aborts processing of this action and unwinds all pending changes.

 

Aborts processing of this action and unwinds all pending changes if the test condition is true

Parameters

  • test - 0 to abort, 1 to ignore
  • code - the error code
Suggest Edits

eosio_exit

Aborts execution of wasm without failing the contract.

 

This method will abort execution of wasm without failing the contract. This is used to bypass all cleanup / destructors that would normally be called.

Parameters

  • code - the exit code Example:
eosio_exit(0);
eosio_exit(1);
eosio_exit(2);
eosio_exit(3);
Suggest Edits

current_time

Get time of the last accepted block.

 

Returns the time in microseconds from 1970 of the current block (block including this action)

Returns

time in seconds from 1970 of the current block Example:

uint64_t timestamp = current_time();
Suggest Edits

now

Returns the time in seconds from 1970 of the block including this action

 

Get time (rounded down to the nearest second) of the current block (i.e. the block including this action)

Returns

time in seconds from 1970 of the current block

Suggest Edits

Transaction

Defines API for sending transactions.

 

SUMMARY

Members Descriptions
public voidsend_deferred(const uint128_t & sender_id,account_namepayer,const char * serialized_transaction,size_t size,uint32_t replace_existing) Sends a deferred transaction.
public intcancel_deferred(const uint128_t & sender_id) Cancels a deferred transaction.
public size_tread_transaction(char * buffer,size_t size) Access a copy of the currently executing transaction.
public size_ttransaction_size() Gets the size of the currently executing transaction.
public inttapos_block_num() Gets the block number used for TAPOS on the currently executing transaction.
public inttapos_block_prefix() Gets the block prefix used for TAPOS on the currently executing transaction.
publictime`[expiration](#expiration)()` Gets the expiration of the currently executing transaction.
public intget_action(uint32_t type,uint32_t index,char * buff,size_t size) Retrieves the indicated action from the active transaction.
public intget_context_free_data(uint32_t index,char * buff,size_t size) Retrieve the signed_transaction.context_free_data[index].
Suggest Edits

send_deferred

Sends a deferred transaction.

 

Sends a deferred transaction.

Parameters

  • sender_id - ID of sender

  • payer - Account paying for RAM

  • serialized_transaction - Pointer of serialized transaction to be deferred

  • size - Size to reserve

Suggest Edits

cancel_deferred

Cancels a deferred transaction.

 

Parameters

  • sender_id - The id of the sender

Precondition

The deferred transaction ID exists.

Precondition

The deferred transaction ID has not yet been published.

Post Condition

Deferred transaction canceled.

Returns

1 if transaction was canceled, 0 if transaction was not found

Example:

id = 0xffffffffffffffff
cancel_deferred( id );
Suggest Edits

read_transaction

Access a copy of the currently executing transaction.

 

Access a copy of the currently executing transaction.

Parameters

  • buffer - a buffer to write the current transaction to

  • size - the size of the buffer, 0 to return required size

Returns

the size of the transaction written to the buffer, or number of bytes that can be copied if size==0 passed

Suggest Edits

transaction_size

Gets the size of the currently executing transaction.

 

Gets the size of the currently executing transaction.

Returns

size of the currently executing transaction

Suggest Edits

tapos_block_num

Gets the block number used for TAPOS on the currently executing transaction.

 

Gets the block number used for TAPOS on the currently executing transaction.

Returns

block number used for TAPOS on the currently executing transaction Example:

int tbn = tapos_block_num();
Suggest Edits

tapos_block_prefix

Gets the block prefix used for TAPOS on the currently executing transaction.

 

Gets the block prefix used for TAPOS on the currently executing transaction.

Returns

block prefix used for TAPOS on the currently executing transaction Example:

int tbp = tapos_block_prefix();
Suggest Edits

expiration

Gets the expiration of the currently executing transaction.

 

Gets the expiration of the currently executing transaction.

Returns

expiration of the currently executing transaction Example:

time tm = expiration();
eosio_print(tm);
Suggest Edits

get_action

Retrieves the indicated action from the active transaction.

 

Retrieves the indicated action from the active transaction.

Parameters

  • type - 0 for context free action, 1 for action

  • index - the index of the requested action

  • buff - output packed buff of the action

  • size - amount of buff read, pass 0 to have size returned

Returns

the size of the action, -1 on failure

Suggest Edits

get_context_free_data

Retrieve the signed_transaction.context_free_data[index].

 

Retrieve the signed_transaction.context_free_data[index]

Parameters

  • index - the index of the context_free_data entry to retrieve

  • buff - output buff of the context_free_data entry

  • size - amount of context_free_data[index] to retrieve into buff, 0 to report required size

Returns

size copied, or context_free_data[index].size() if 0 passed for size, or -1 if index not valid

Suggest Edits

Privileged

 

privilegedcapi

Defines C Privileged API.

SUMMARY

Members Descriptions
public voidset_resource_limits(account_nameaccount,int64_t ram_bytes,int64_t net_weight,int64_t cpu_weight) Set the resource limit of an account Set the resource limit of an account.
public int64_tset_proposed_producers(char * producer_data,uint32_t producer_data_size) Propose the new active producer schedule
public voidset_active_producers(char * producer_data,uint32_t producer_data_size) Set new active producers Set new active producers. Producers will only be activated once the block which starts the next round is irrreversible.
public boolis_privileged(account_nameaccount) Check if an account is privileged
public voidset_privileged(account_nameaccount,bool is_priv) Set the privileged status of an account Set the privileged status of an account.
public voidset_blockchain_parameters_packed(char * data,uint32_t datalen) Set the blockchain parameters
public uint32_tget_blockchain_parameters_packed(char * data,uint32_t datalen) Retrieve the blockchain parameters parameters.
public voidactivate_feature(int64_t f) Activate new feature Activate new feature.
Suggest Edits

set_resource_limits

Set the resource limit of an account Set the resource limit of an account.

 

Parameters

  • account - name of the account whose resource limit to be set

  • ram_bytes - ram limit

  • net_weight - net limit

  • cpu_weight - cput limit

set_proposed_producers

Propose the new active producer schedule

Parameters

  • producer_data - packed data of produce_keys in the appropriate producer schedule order

  • producer_data_size - size of the data buffer

Returns

-1 if proposing a new producer schedule was unsuccessful, otherwise returns the version of the new proposed schedule

Suggest Edits

set_active_producers

Set new active producers Set new active producers. Producers will only be activated once the block which starts the next round is irrreversible.

 

Parameters

  • producer_data - pointer to producer schedule packed as bytes

  • producer_data_size - size of the packed producer schedule

Precondition

producer_data is a valid pointer to a range of memory at least producer_data_size bytes long that contains serialized produced schedule data

Suggest Edits

is_privileged

Check if an account is privileged Check if an account is privileged.

 

Parameters

  • account - name of the account to be checked

Returns

true if the account is privileged

Returns

false if the account is not privileged

Suggest Edits

set_privileged

Set the privileged status of an account Set the privileged status of an account.

 

Parameters

  • account - name of the account whose privileged account to be set

  • is_priv - privileged status

Suggest Edits

set_blockchain_parameters_packed

Set the blockchain parameters Set the blockchain parameters.

 

Parameters

  • data - pointer to blockchain parameters packed as bytes
  • datalen - size of the packed blockchain parameters

Precondition

data is a valid pointer to a range of memory at least datalen bytes long that contains packed blockchain params data

Suggest Edits

get_blockchain_parameters_packed

Retrieve the blockchain parameters

 

Parameters

  • data - output buffer of the blockchain parameters, only retrieved if sufficent size to hold packed data.

  • datalen - size of the data buffer, 0 to report required size.

Returns

size of the blockchain parameters

Precondition

data is a valid pointer to a range of memory at least datalen bytes long

Post Condition

data is filled with packed blockchain parameters

Suggest Edits

activate_feature

Activate new feature Activate new feature.

 

Parameters

  • f - name (identifier) of the feature to be activated
Suggest Edits

Memory

Defines common memory functions.

 

SUMMARY

Members Descriptions
public void *malloc(size_t size) Allocate additional memory.
public void *calloc(size_t count,size_t size) Allocate a block of memory for an array of count elements, each of them size bytes long, and initializes all bits with 0.
public void *realloc(void * ptr,size_t size) Reallocate the given area of memory.
public voidfree(void * ptr) Deallocates the given area of memory.
Suggest Edits

malloc

Allocate additional memory.

 

Parameters

  • size - Number of additional bytes to be allocated

Returns

void* - Pointer to start of the new allocated memory

Suggest Edits

calloc

Allocate a block of memory for an array of count elements, each of them size bytes long, and initializes all bits with 0.

 

Parameters

  • count - Number of elements to allocate

  • size - Size of each element

Returns

void* - Pointer to start of the new allocated memory

Suggest Edits

realloc

Reallocate the given area of memory.

 

Reallocate the given area of memory, which is allocated by malloc()), calloc()), or realloc()) previously

Parameters

  • ptr - Pointer to the memory area to be reallocated

  • size - New size of the memory

Returns

void* - Pointer to the new reallocated memory

Suggest Edits

free

Deallocates the given area of memory.

 

Deallocates the given area of memory which is previously allocated by malloc()), calloc()), or realloc())

Parameters

  • ptr - Pointer to the memory to be deallocated
Suggest Edits

Action

Defines type-safe C++ wrapers for querying action and sending action.

 

There are some methods from the Action C API that can be used directly from C++

Additional documentation for group

SUMMARY

Members Descriptions
defineSEND_INLINE_ACTION Send inline action.
defineACTION Extend a new defined action with the action meta.
public template<> Tunpack_action_data() Interpret the action body as type T.
public template<> voidrequire_recipient(account_namename,accounts... remaining_accounts) Notify an account for this action.
public voidrequire_auth(const permission_level & level) Require the specified authorization for this action.
structeosio::permission_level Packed representation of a permission level (Authorization)
structeosio::action Packed representation of an action.
structeosio::action_meta Base class to derive a new defined action from.
Suggest Edits

action [struct]

Packed representation of an action.

 

This is the packed representation of an action along with meta-data about the authorization levels.

Summary

Members Descriptions
publicaccount_name`[account`](#account) Name of the account the action is intended for.
publicaction_name`[name`](#name) Name of the action.
public vector<permission_level>authorization List of permissions that authorize this action.
publicbytes`[data`](#data) Payload data.
publicaction() = default Construct a new action object.
public template<> <br/>inlineaction(vector<permission_level> && auth,const Action & value) Construct a new action object with the given permission and action struct.
public template<> <br/>inlineaction(constpermission_level& auth,const Action & value) Construct a new action object with the given list of permissions and action struct.
public template<> <br/>inlineaction(const Action & value) Construct a new action object with the given action struct.
public template<> <br/>inlineaction(constpermission_level& auth,account_namea,action_namen,T && value) Construct a new action object with the given permission, action receiver, action name, action struct.
public template<> <br/>inlineaction(vector<permission_level> auths,account_namea,action_namen,T && value) Construct a new action object with the given list of permissions, action receiver, action name, action struct.
public inlineEOSLIB_SERIALIZE(action,(`account)(name)(authorization)(data`)) const Send the action as inline action.
public inline voidsend_context_free() const Send the action as inline context free action.
public template<> <br/>inline Tdata_as() Retrieve the unpacked data as T.

Members

publicaccount_name`[account`](#account)

Name of the account the action is intended for.

Name of the account the action is intended for

publicaction_name`[name`](#name)

Name of the action.

Name of the action

public vector<permission_level>authorization

List of permissions that authorize this action.

List of permissions that authorize this action

publicbytes`[data`](#data)

Payload data.

Payload data

publicaction() = default

Construct a new action object.

Default Constructor

public template<> <br/>inlineaction(vector<permission_level> && auth,const Action & value)

Construct a new action object with the given permission and action struct.

Construct a new action object with the given permission and action struct

Parameters

  • Action - Type of action struct

Parameters

  • auth - The permission that authorizes this action

  • value - The action struct that will be serialized via pack into data

public template<> <br/>inlineaction(constpermission_level& auth,const Action & value)

Construct a new action object with the given list of permissions and action struct.

Construct a new action object with the given list of permissions and action struct

Parameters

  • Action - Type of action struct

Parameters

  • auth - The list of permissions that authorizes this action

  • value - The action struct that will be serialized via pack into data

public template<> <br/>inlineaction(const Action & value)

Construct a new action object with the given action struct.

Construct a new action object with the given action struct

Parameters

  • Action - Type of action struct

Parameters

  • value - The action struct that will be serialized via pack into data

public template<> <br/>inlineaction(constpermission_level& auth,account_namea,action_namen,T && value)

Construct a new action object with the given permission, action receiver, action name, action struct.

Construct a new action object with the given action struct

Parameters

  • T - Type of action struct

Parameters

  • auth - The permissions that authorizes this action

  • a - The name of the account this action is intended for (action receiver)

  • n - The name of the action

  • value - The action struct that will be serialized via pack into data

public template<> <br/>inlineaction(vector<permission_level> auths,account_namea,action_namen,T && value)

Construct a new action object with the given list of permissions, action receiver, action name, action struct.

Construct a new action object with the given action struct

Parameters

  • T - Type of action struct

Parameters

  • auths - The list of permissions that authorize this action

  • a - The name of the account this action is intended for (action receiver)

  • n - The name of the action

  • value - The action struct that will be serialized via pack into data

public inlineEOSLIB_SERIALIZE(action,(`account)(name)(authorization)(data`)) const

Send the action as inline action.

Send the action as inline action

public inline voidsend_context_free() const

Send the action as inline context free action.

Send the action as inline context free action

Precondition

This action should not contain any authorizations

public template<> <br/>inline Tdata_as()

Retrieve the unpacked data as T.

Retrieve the unpacked data as T

Parameters

  • T expected type of data

Returns

the action data

Base class to derive a new defined action from.

Base class to derive a new defined action from so it can take advantage of the dispatcher

Parameters

  • Account - The account this action is intended for

  • Name - The name of the action

Suggest Edits

action_meta [struct]

Base class to derive a new defined action from.

 

Base class to derive a new defined action from so it can take advantage of the dispatcher

Parameters

  • Account - The account this action is intended for
  • Name - The name of the action
Suggest Edits

permission_level (struct)

Packed representation of a permission level (Authorization)

 

Summary

Members Descriptions
publicaccount_name`[actor`](#actor) Name of the account who owns this permission.
publicpermission_name`[permission`](#permission) Name of the permission.
public inlinepermission_level(account_namea,permission_namep) Construct a new permission level object.
public inlinepermission_level() Construct a new permission level object.

Members

publicaccount_name`[actor`](#actor)

Name of the account who owns this permission.

publicpermission_name`[permission`](#permission)

Name of the permission

public inlinepermission_level(account_namea,permission_namep)

Construct a new permission level object with actor name and permission name

Parameters

  • a - Name of the account who owns this authorization
  • p - Name of the permission

public inlinepermission_level()

Construct a new permission level object. (Default Constructor)

Suggest Edits

SEND_INLINE_ACTION

Send inline action.

 

Send inline action

Parameters

  • CONTRACT - The account this action is intended for
  • NAME - The name of the action
  • ... - The member of the action specified as ("action_member1_name", action_member1_value)("action_member2_name", action_member2_value)
Suggest Edits

ACTION

Extend a new defined action with the action meta.

 

Extend a new defined action with theaction meta, so it can work with the dispatcher

Parameters

  • CODE - The account this action is intended for
  • NAME - The name of the action
Suggest Edits

unpack_action_data

Interpret the action body as type T.

 

This method unpacks the current action at type T.

Returns

Unpacked action data casted as T.

Example:

struct dummy_action {
  char a; //1
  unsigned long long b; //8
  int  c; //4

  EOSLIB_SERIALIZE( dummy_action, (a)(b)(c) )
};
dummy_action msg = unpack_action_data();

#

Suggest Edits

Asset

Defines CPP API for managing assets.

 

Summary

Members Descriptions
public int64_t amount The amount of the asset.
public symbol_type symbol The symbol name of the asset.
public inline explicit asset(int64_t a,symbol_types) Construct a new asset object.
public inline bool is_amount_within_range () const Check if the amount doesn't exceed the max amount.
public inline bool is_valid () const Check if the asset is valid.
public inline voidset_amount(int64_t a) Set the amount of the asset.
public inlineasset`[operator-](#operator-)() const` Unary minus operator.
public inlineasset&operator-=(constasset& a) Subtraction assignment operator.
public inlineasset&operator+=(constasset& a) Addition Assignment operator.
public inlineasset&operator*=(int64_t a) Multiplication assignment operator, with a number.
public inlineasset&operator/=(int64_t a) Division assignment operator, with a number.
public inline voidprint() const Print the asset

publicamount`

The amount of the asset

publicsymbol_type`[symbol`](#symbol)

The symbol name of the asset

Suggest Edits

symbol_type

 
public inline explicit asset (int64_t a, symbol_type s)
`

Construct a new asset given the symbol name and the amount

Parameters

  • a - The amount of the asset

  • s - THe name of the symbol, default to CORE_SYMBOL

public inline boolis_amount_within_range() const

Check if the amount doesn't exceed the max amount

Returns

true - if the amount doesn't exceed the max amount

Returns

false - otherwise

Suggest Edits

is_valid

Check if the asset is valid. A valid asset has its amount <= max_amount and its symbol name valid

 
public inline bool is_valid() const

Check if the asset is valid. A valid asset has its amount <= max_amount and its symbol name valid

Returns

true - if the asset is valid

Returns

false - otherwise

Suggest Edits

set_amount

 
public inline void set_amount(int64_t a)

Set the amount of the asset

Parameters

  • a - New amount for the asset
Suggest Edits

operator-

 
public inline asset operator-() const

Unary minus operator

Returns

asset - New asset with its amount is the negative amount of this asset

Suggest Edits

operator-=

 
public inline asset & operator-=(const asset & a)

Subtraction assignment operator

Parameters

  • a - Another asset to subtract this asset with

Returns

asset& - Reference to this asset

Post Condition

The amount of this asset is subtracted by the amount of asset a

Suggest Edits

operator+=

Addition Assignment operator

 
public inline asset & operator+=(const asset & a)

Parameters

  • a - Another asset to subtract this asset with

Returns

asset& - Reference to this asset

Post Condition

The amount of this asset is added with the amount of asset a

Suggest Edits

operator*=

Multiplication assignment operator, with a number.

 
public inline asset& operator *=(int64_t a)

Multiplication assignment operator. Multiply the amount of this asset with a number and then assign the value to itself.

Parameters

  • a - The multiplier for the asset's amount

Returns

asset - Reference to this asset

Post Condition

The amount of this asset is multiplied by a

Suggest Edits

operator/=

Division assignment operator, with a number.

 
public inline asset & operator/=(int64_t a)

Division assignment operator. Divide the amount of this asset with a number and then assign the value to itself.

Parameters

  • a - The divisor for the asset's amount

Returns

asset - Reference to this asset

Post Condition

The amount of this asset is divided by a

Suggest Edits

print

Print the asset

 
public inline void print() const
Suggest Edits

Extended Asset

Extended asset which stores the information of the owner of the asset.

 
struct eosio::extended_asset
  : public eosio::asset

Extended asset which stores the information of the owner of the asset

Summary

Members Descriptions
publicaccount_name`[contract`](#contract) The owner of the asset.
public inlineextended_symbol`[get_extended_symbol](#get_extended_symbol)() const` Get the extended symbol of the asset.
publicextended_asset() = default Construct a new extended asset object.
public inlineextended_asset(int64_t v,extended_symbols) Construct a new extended asset object.
public inlineextended_asset(asseta,account_namec) Construct a new extended asset object.
public inline voidprint() const Print the extended asset
public inlineextended_asset`[operator-](#operator-)() const` Unary minus operator.

Members

publicaccount_name`[contract`](#contract)

The owner of the asset

public inlineextended_symbol`[get_extended_symbol](#get_extended_symbol)() const`

Get the extended symbol of the asset

Returns

extended_symbol - The extended symbol of the asset

publicextended_asset() = default

Construct a new extended asset object.

Default constructor

public inlineextended_asset(int64_t v,extended_symbols)

Construct a new extended asset given the amount and extended symbol

public inlineextended_asset(asseta,account_namec)

Construct a new extended asset given the asset and owner name

public inline voidprint() const

Print the extended asset

public inlineextended_asset`[operator-](#operator-)() const`

Unary minus operator

Returns

extended_asset - New extended asset with its amount is the negative amount of this extended asset

Suggest Edits

Transaction

 

group transactioncppapi

Type-safe C++ wrappers for transaction C API.

There are some methods from the Transaction C API that can be used directly from C++

Summary

Members Descriptions
public inline actionget_action(uint32_t type,uint32_t index) Retrieve the indicated action from the active transaction.
public inline voidcheck_auth(const bytes & trx_packed,const vector< permission_level > & permissions)
public inline voidcheck_auth(const char * serialized_transaction,size_t size,const vector< permission_level > & permissions)
public inline voidcheck_auth(const transaction & trx,const vector< permission_level > & permissions)
classeosio::transaction_header
classeosio::transaction
classeosio::deferred_transaction

Members

public inline actionget_action(uint32_t type,uint32_t index)

Retrieve the indicated action from the active transaction.

Parameters

  • type - 0 for context free action, 1 for action

  • index - the index of the requested action

Returns

the indicated action

public inline voidcheck_auth(const bytes & trx_packed,const vector< permission_level > & permissions)

public inline voidcheck_auth(const char * serialized_transaction,size_t size,const vector< permission_level > & permissions)

public inline voidcheck_auth(const transaction & trx,const vector< permission_level > & permissions)

class eosio::transaction_header

Summary

Members Descriptions
publictime`[expiration`](#classeosio_1_1transaction__header_1a2d01d4d651eaab53ef0796bf138ed691)
publicregion_id`[region`](#classeosio_1_1transaction__header_1a3f03fd4c381e7307f3709d861320e6ff)
public uint16_tref_block_num
public uint32_tref_block_prefix
publicunsigned_int`[net_usage_words`](#classeosio_1_1transaction__header_1a0d66dd30a2c0660eda03dd89cc7c5041)
publicunsigned_int`[kcpu_usage`](#classeosio_1_1transaction__header_1aeece6ee784f4fee73988cbccd017ca57) number of 8 byte words this transaction can serialize into after compressions
publicunsigned_int`[delay_sec`](#classeosio_1_1transaction__header_1adbe5ee5f38a82db68162188c49d62f39) number of CPU usage units to bill transaction for
public inlinetransaction_header(timeexp,region_idr)

Members

publictime`[expiration`](#classeosio_1_1transaction__header_1a2d01d4d651eaab53ef0796bf138ed691)

publicregion_id`[region`](#classeosio_1_1transaction__header_1a3f03fd4c381e7307f3709d861320e6ff)

public uint16_tref_block_num

public uint32_tref_block_prefix

publicunsigned_int`[net_usage_words`](#classeosio_1_1transaction__header_1a0d66dd30a2c0660eda03dd89cc7c5041)

publicunsigned_int`[kcpu_usage`](#classeosio_1_1transaction__header_1aeece6ee784f4fee73988cbccd017ca57)

number of 8 byte words this transaction can serialize into after compressions

publicunsigned_int`[delay_sec`](#classeosio_1_1transaction__header_1adbe5ee5f38a82db68162188c49d62f39)

number of CPU usage units to bill transaction for

public inlinetransaction_header(timeexp,region_idr)

class eosio::transaction

class eosio::transaction
  : public eosio::transaction_header

Summary

Members Descriptions
public vector<action>context_free_actions
public vector<action>actions
public inlinetransaction(timeexp,region_idr)
public inline voidsend(uint64_t sender_id,account_namepayer) const

Members

public vector<action>context_free_actions

public vector<action>actions

public inlinetransaction(timeexp,region_idr)

public inline voidsend(uint64_t sender_id,account_namepayer) const

class eosio::deferred_transaction

class eosio::deferred_transaction
  : public eosio::transaction

Summary

Members Descriptions
public uint128_tsender_id
publicaccount_name`[sender`](#classeosio_1_1deferred__transaction_1a82441339af3291e5425b338098d2f896)
publicaccount_name`[payer`](#classeosio_1_1deferred__transaction_1ab9a8613f83abbdbd9e1101d56fa66a20)
publictime`[execute_after`](#classeosio_1_1deferred__transaction_1a2f80b200b62fa63e8ce8cd68f7683d98)

Members

public uint128_tsender_id

publicaccount_name`[sender`](#classeosio_1_1deferred__transaction_1a82441339af3291e5425b338098d2f896)

publicaccount_name`[payer`](#classeosio_1_1deferred__transaction_1ab9a8613f83abbdbd9e1101d56fa66a20)

publictime`[execute_after`](#classeosio_1_1deferred__transaction_1a2f80b200b62fa63e8ce8cd68f7683d98)

Suggest Edits

Console

Defines C++ wrapper to log/print text messages.

 

This API uses C++ variadic templates and type detection to make it easy to print any native type. You can even overload the [print()](#print()) method for your own custom types.

Example:

print( "hello world, this is a number: ", 5 );

Overriding Print for your TypesThere are two ways to overload print:* implement void print( const T& )

  • implement T::print()const

SUMMARY

Members Descriptions
public template<> <br/>inline voidprint_f(const char * s,Arg val,Args... rest) Prints formatted string.
public template<> <br/>voidprint(Arg && a,Args &&... args) Print out value / list of values.
public template<> <br/>inline iostream &operator<<(iostream & out,const T & v) Overload c++ iostream.
classeosio::iostream Simulate C++ style streams
Suggest Edits

print_f

Prints formatted string.

 

Prints formatted string. It behaves similar to C printf/

Parameters

  • Arg - Type of the value used to replace the format specifier

  • Args - Type of the value used to replace the format specifier

Parameters

  • s - Null terminated string with to be printed (it can contains format specifier)

  • val - The value used to replace the format specifier

  • rest - The values used to replace the format specifier

Example:

print_f("Number of apples: %", 10);
Suggest Edits

print

Print out value / list of values.

 

Parameters

  • a - The value to be printed

  • args - The other values to be printed

Example:

const char *s = "Hello World!";
uint64_t unsigned_64_bit_int = 1e+18;
uint128_t unsigned_128_bit_int (87654323456);
uint64_t string_as_unsigned_64_bit = N(abcde);
print(s , unsigned_64_bit_int, unsigned_128_bit_int, string_as_unsigned_64_bit);
// Ouput: Hello World!100000000000000000087654323456abcde
Suggest Edits

operator<<

Overload c++ iostream.

 

Overload c++ iostream

Parameters

  • out - Output strem

  • v - The value to be printed

Returns

iostream& - Reference to the input output stream

Example:

const char *s = "Hello World!";
uint64_t unsigned_64_bit_int = 1e+18;
uint128_t unsigned_128_bit_int (87654323456);
uint64_t string_as_unsigned_64_bit = N(abcde);
std::out << s << " " << unsigned_64_bit_int << " "  << unsigned_128_bit_int << " " << string_as_unsigned_64_bit;
// Output: Hello World! 1000000000000000000 87654323456 abcde
Suggest Edits

Contract Type

Defines contract type which is the base class for every EOSIO contract

 
Suggest Edits

get_self

Get this contract name.

 

Returns

account_name - The name of this contract

Suggest Edits

Dispatcher

Defines C++ functions to dispatch action to proper action handler inside a contract.

 

SUMMARY

Members Descriptions
public template<> <br/>boolexecute_action(T * obj,void(Q::*)(Args...) func) Unpack the received action and execute the correponding action handler.
Suggest Edits

EOSIO_ABI

Dispatcher macro for apply handlers

 

The EOSIO_ABI is a convenience macro that accepts a "class" and public methods from that class that dispatches actions. Data passed to the action is unpacked and applied positionally to the method in the class.

Parameters

  • TYPE - The contract class that has the correponding action handler, this contract should be derived from eosio::contract
  • MEMBERS - The namespace of the action handler function

Returns

n/a

Example

EOSIO_ABI( myclass, (myaction1)(myaction2)(myaction3) )
Suggest Edits

execute_action

Unpack the received action and execute the correponding action handler.

 

Unpack the received action and execute the correponding action handler

Parameters

  • T - The contract class that has the correponding action handler, this contract should be derived from eosio::contract
  • Q - The namespace of the action handler function
  • Args - The arguments that the action handler accepts, i.e. members of the action

Parameters

  • obj - The contract object that has the correponding action handler
  • func - The action handler

Returns

true

Defines common memory functions.

SUMMARY

Members Descriptions
public void *malloc(size_t size) Allocate additional memory.
public void *calloc(size_t count,size_t size) Allocate a block of memory for an array of count elements, each of them size bytes long, and initializes all bits with 0.
public void *realloc(void * ptr,size_t size) Reallocate the given area of memory.
public voidfree(void * ptr) Deallocates the given area of memory.
Suggest Edits

malloc

Allocate additional memory.

 

Allocate additional memory

Parameters

  • size - Number of additional bytes to be allocated

Returns

void* - Pointer to start of the new allocated memory

Suggest Edits

calloc

Allocate a block of memory for an array of count elements, each of them size bytes long, and initializes all bits with 0.

 

Parameters

  • count - Number of elements to allocate

  • size - Size of each element

Returns

void* - Pointer to start of the new allocated memory

Suggest Edits

realloc

Reallocate the given area of memory.

 

Reallocate the given area of memory, which is allocated by malloc()), calloc()), or realloc()) previously

Parameters

  • ptr - Pointer to the memory area to be reallocated

  • size - New size of the memory

Returns

void* - Pointer to the new reallocated memory

Suggest Edits

free

Deallocates the given area of memory.

 

Deallocates the given area of memory which is previously allocated by malloc()), calloc()), or realloc())

Parameters

  • ptr - Pointer to the memory to be deallocated
Suggest Edits

Priviledged

Defines C++ Privileged API.

 

SUMMARY

Members Descriptions
public voidset_blockchain_parameters(consteosio::blockchain_parameters& params) Set the blockchain parameters Set the blockchain parameters.
public voidget_blockchain_parameters(eosio::blockchain_parameters& params) Retrieve the blolckchain parameters Retrieve the blolckchain parameters.
structeosio::blockchain_parameters Tunable blockchain configuration that can be changed via consensus.
Suggest Edits

set_blockchain_parameters

Set the blockchain parameters Set the blockchain parameters.

 

Parameters

  • params - New blockchain parameters to set

get_blockchain_parameters

Retrieve the blolckchain parameters Retrieve the blolckchain parameters.

Parameters

  • params - It will be replaced with the retrieved blockchain params

Tunable blockchain configuration that can be changed via consensus.

Tunable blockchain configuration that can be changed via consensus

Suggest Edits

Transactions

 
Suggest Edits

get_action

 

Retrieve the indicated action from the active transaction.

Parameters

  • type - 0 for context free action, 1 for action

  • index - the index of the requested action

Returns

the indicated action

Suggest Edits

Multi-Index

Defines EOSIO Multi Index Table.

 

EOSIO Multi-Index API provides a C++ interface to the EOSIO database. It is patterned after Boost Multi Index Container. EOSIO Multi-Index table requires exactly a uint64_t primary key. For the table to be able to retrieve the primary key, the object stored inside the table is required to have a const member function called primary_key() that returns uint64_t. EOSIO Multi-Index table also supports up to 16 secondary indices. The type of the secondary indices could be any of:

  • uint64_t

  • uint128_t

  • uint256_t

  • double

  • long double

Parameters

  • TableName - name of the table

  • T - type of the data stored inside the table

  • Indices - secondary indices for the table, up to 16 indices is supported here

Example:

#include 
using namespace eosio;
class mycontract: contract {
  struct record {
    uint64_t    primary;
    uint64_t    secondary_1;
    uint128_t   secondary_2;
    uint256_t   secondary_3;
    double      secondary_4;
    long double secondary_5;
    uint64_t primary_key() const { return primary; }
    uint64_t get_secondary_1() const { return secondary_1; }
    uint128_t get_secondary_2() const { return secondary_2; }
    uint256_t get_secondary_3() const { return secondary_3; }
    double get_secondary_4() const { return secondary_4; }
    long double get_secondary_5() const { return secondary_5; }
    EOSLIB_SERIALIZE( record, (primary)(secondary_1)(secondary_2)(secondary_3)(secondary_4)(secondary_5) )
  };
  public:
    mycontract( account_name self ):contract(self){}
    void myaction() {
      auto code = _self;
      auto scope = _self;
      multi_index >,
        indexed_by< N(bysecondary2), const_mem_fun >,
        indexed_by< N(bysecondary3), const_mem_fun >,
        indexed_by< N(bysecondary4), const_mem_fun >,
        indexed_by< N(bysecondary5), const_mem_fun >
      > table( code, scope);
    }
}
EOSIO_ABI( mycontract, (myaction) )

Summary

Members Descriptions
public inline multi_index(uint64_t code,uint64_t scope) load_object_by_primary_iterator
public inline uint64_t get_code() const Returns the code member property.
public inline uint64_tget_scope() const Returns the scope member property.
public inline const_iterator cbegin() const Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.
public inline const_iterator begin() const Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.
public inline const_iterator cend() const Returns an iterator pointing to the object_type with the highest primary key value in the Multi-Index table.
public inline const_iterator end() const Returns an iterator pointing to the object_type with the highest primary key value in the Multi-Index table.
public inline const_reverse_iterator crbegin() const Returns a reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.
public inline const_reverse_iterator rbegin() const Returns a reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.
public inline const_reverse_iterator crend() const Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.
public inline const_reverse_iterator [rend](#rend)() const` Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.
public inline const_iterator lower_bound (uint64_t primary) const Searches for the object_type with the lowest primary key that is greater than or equal to a given primary key.
public inline const_iterator upper_bound (uint64_t primary) const Searches for the object_type with the highest primary key that is less than or equal to a given primary key.
public inline uint64_t available_primary_key() const Returns an available primary key.
public template<> <br/> inline auto get_index() Returns an appropriately typed Secondary Index.
public template<> <br/> inline auto get_index() const Returns an appropriately typed Secondary Index.
public inline const_iterator iterator_to(const T & obj) const Returns an iterator to the given object in a Multi-Index table.
public template<> <br/> inline const_iterator`[emplace](#emplace)(uint64_t payer,Lambda && constructor)` Adds a new object (i.e., row) to the table.
public template<> <br/> inline void modify(const_iteratoritr,uint64_t payer,Lambda && updater) Modifies an existing object in a table.
public template<> <br/> inline void modify(const T & obj,uint64_t payer,Lambda && updater) Modifies an existing object in a table.
public inline const T & get(uint64_t primary,const char * error_msg) const Retrieves an existing object from a table using its primary key.
public inline const_iterator`[find](#find)(uint64_t primary) const` Search for an existing object in a table using its primary key.
public inline const_iterator`[erase](#erase)([const_iterator](#const_iterator) itr)` Remove an existing object from a table using its primary key.
public inline void erase(const T & obj) Remove an existing object from a table using its primary key.
typedef const_reverse_iterator struct multi_index::const_iterator

Members

public inline multi_index(uint64_t code,uint64_t scope)

load_object_by_primary_iterator

Constructs an instance of a Multi-Index table.

Parameters

  • code - Account that owns table

  • scope - Scope identifier within the code hierarchy

Precondition

code and scope member properties are initialized

Post Condition

each secondary index table initialized

Post Condition

Secondary indices are updated to refer to the newly added object. If the secondary index tables do not exist, they are created.

Post Condition

The payer is charged for the storage usage of the new object and, if the table (and secondary index tables) must be created, for the overhead of the table creation.

Notes The [eosio::multi_index](#eosio::multi_index) template has template parameters <uint64_t TableName, typename T, typename... Indices>, where:

  • TableName is the name of the table, maximum 12 characters long, characters in the name from the set of lowercase letters, digits 1 to 5, and the "." (period) character;

  • T is the object type (i.e., row definition);

  • Indices is a list of up to 16 secondary indices.

  • Each must be a default constructable class or struct

  • Each must have a function call operator that takes a const reference to the table object type and returns either a secondary key type or a reference to a secondary key type

  • It is recommended to use the eosio::const_mem_fun template, which is a type alias to the boost::multi_index::const_mem_fun. See the documentation for the Boost const_mem_fun key extractor for more details.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

get_code

Returns the code member property.

 

Returns the code member property.

Returns

Account name of the Code that owns the Primary Table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(N(dan), N(dan)); // code, scope
      eosio_assert(addresses.get_code() == N(dan), "Codes don't match.");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

get_scope

Returns the scope member property.

 

Returns the scope member property.

Returns

Scope id of the Scope within the Code of the Current Receiver under which the desired Primary Table instance can be found.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(N(dan), N(dan)); // code, scope
      eosio_assert(addresses.get_scope() == N(dan), "Scopes don't match");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

cbegin

Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

 

Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

Returns

An iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr == addresses.cbegin(), "Only address is not at front.");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

begin

Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

 

Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

Returns

An iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr == addresses.begin(), "Only address is not at front.");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

cend

Returns an iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

 

Returns an iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Returns

An iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr != addresses.cend(), "Address for account doesn't exist");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

end

Returns an iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

 

Returns an iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Returns

An iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr != addresses.end(), "Address for account doesn't exist");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

crbegin

Returns a reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

 

Returns a reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Returns

A reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
      });
      auto itr = addresses.crbegin();
      eosio_assert(itr->account_name == N(dan), "Incorrect Last Record ");
      itr++;
      eosio_assert(itr->account_name == N(brendan), "Incorrect Second Last Record");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

rbegin

Returns a reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

 

Returns

A reverse iterator pointing to the object_type with the highest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
      });
      auto itr = addresses.rbegin();
      eosio_assert(itr->account_name == N(dan), "Incorrect Last Record ");
      itr++;
      eosio_assert(itr->account_name == N(brendan), "Incorrect Second Last Record");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

crend

Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

 

Returns

An iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
      });
      auto itr = addresses.crend();
      itr--;
      eosio_assert(itr->account_name == N(brendan), "Incorrect First Record ");
      itr--;
      eosio_assert(itr->account_name == N(dan), "Incorrect Second Record");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

rend

Returns an iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

 

Returns

An iterator pointing to the object_type with the lowest primary key value in the Multi-Index table.

Example

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
      });
      auto itr = addresses.rend();
      itr--;
      eosio_assert(itr->account_name == N(brendan), "Incorrect First Record ");
      itr--;
      eosio_assert(itr->account_name == N(dan), "Incorrect Second Record");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

lower_bound

Searches for the object_type with the lowest primary key that is greater than or equal to a given primary key.

 

Parameters

  • primary - Primary key that establishes the target value for the lower bound search.

Returns

An iterator pointing to the object_type that has the lowest primary key that is greater than or equal to primary. If an object could not be found, it will return the end iterator. If the table does not exist** it will return -1.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint32_t zip = 0;
     uint64_t primary_key() const { return account_name; }
     uint64_t by_zip() const { return zip; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state)(zip) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address, indexed_by< N(zip), const_mem_fun > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
        address.zip = 93446;
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
        address.zip = 93445;
      });
      uint32_t zipnumb = 93445;
      auto zip_index = addresses.get_index();
      auto itr = zip_index.lower_bound(zipnumb);
      eosio_assert(itr->account_name == N(brendan), "Incorrect First Lower Bound Record ");
      itr++;
      eosio_assert(itr->account_name == N(dan), "Incorrect Second Lower Bound Record");
      itr++;
      eosio_assert(itr == zip_index.end(), "Incorrect End of Iterator");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

upper_bound

Searches for the object_type with the highest primary key that is less than or equal to a given primary key.

 

Searches for the object_type with the highest primary key that is less than or equal to a given primary key.

Parameters

  • primary - Primary key that establishes the target value for the upper bound search

Returns

An iterator pointing to the object_type that has the highest primary key that is less than or equal to primary. If an object could not be found, it will return the end iterator. If the table does not exist** it will return -1.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint32_t zip = 0;
     uint64_t liked = 0;
     uint64_t primary_key() const { return account_name; }
     uint64_t by_zip() const { return zip; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state)(zip) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address, indexed_by< N(zip), const_mem_fun > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
        address.zip = 93446;
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
        address.zip = 93445;
      });
      uint32_t zipnumb = 93445;
      auto zip_index = addresses.get_index();
      auto itr = zip_index.upper_bound(zipnumb);
      eosio_assert(itr->account_name == N(dan), "Incorrect First Upper Bound Record ");
      itr++;
      eosio_assert(itr == zip_index.end(), "Incorrect End of Iterator");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

available_primary_key

Returns an available primary key.

 

Returns

An available (unused) primary key value.

Notes: Intended to be used in tables in which the primary keys of the table are strictly intended to be auto-incrementing, and thus will never be set to custom values by the contract. Violating this expectation could result in the table appearing to be full due to inability to allocate an available primary key. Ideally this method would only be used to determine the appropriate primary key to use within new objects added to a table in which the primary keys of the table are strictly intended from the beginning to be autoincrementing and thus will not ever be set to custom arbitrary values by the contract. Violating this agreement could result in the table appearing full when in reality there is plenty of space left.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t key;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return key; }
     EOSLIB_SERIALIZE( address, (key)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.key = addresses.available_primary_key();
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

get_index

Returns an appropriately typed Secondary Index.

 

Returns an appropriately typed Secondary Index.

Parameters

  • IndexName - the ID of the desired secondary index

Returns

An index of the appropriate type: Primitive 64-bit unsigned integer key (idx64), Primitive 128-bit unsigned integer key (idx128), 128-bit fixed-size lexicographical key (idx128), 256-bit fixed-size lexicographical key (idx256), Floating point key, Double precision floating point key, Long Double (quadruple) precision floating point key

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint32_t zip = 0;
     uint64_t primary_key() const { return account_name; }
     uint64_t by_zip() const { return zip; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state)(zip) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address, indexed_by< N(zip), const_mem_fun > address_index;
    void myaction() {
      address_index addresses(_self, _self);  // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
        address.zip = 93446;
      });
      uint32_t zipnumb = 93446;
      auto zip_index = addresses.get_index();
      auto itr = zip_index.find(zipnumb);
      eosio_assert(itr->account_name == N(dan), "Incorrect Record ");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

iterator_to

Returns an iterator to the given object in a Multi-Index table.

 

Parameters

  • obj - A reference to the desired object

Returns

An iterator to the given object

Example

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint32_t zip = 0;
     uint64_t primary_key() const { return account_name; }
     uint64_t by_zip() const { return zip; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state)(zip) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address, indexed_by< N(zip), const_mem_fun > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
        address.zip = 93446;
      });
      addresses.emplace(payer, [&](auto& address) {
        address.account_name = N(brendan);
        address.first_name = "Brendan";
        address.last_name = "Blumer";
        address.street = "1 EOS Way";
        address.city = "Hong Kong";
        address.state = "HK";
        address.zip = 93445;
      });
      auto user = addresses.get(N(dan));
      auto itr = address.find(N(dan));
      eosio_assert(iterator_to(user) == itr, "Invalid iterator");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

emplace

Adds a new object (i.e., row) to the table.

 

Parameters

  • payer - Account name of the payer for the Storage usage of the new object

  • constructor - Lambda function that does an in-place initialization of the object to be created in the table

Precondition

A multi index table has been instantiated

Post Condition

  • A new object is created in the Multi-Index table, with a unique primary key (as specified in the object). The object is serialized and written to the table. If the table does not exist, it is created.
  • Secondary indices are updated to refer to the newly added object. If the secondary index tables do not exist, they are created.
  • The payer is charged for the storage usage of the new object and, if the table (and secondary index tables) must be created, for the overhead of the table creation.

Returns

A primary key iterator to the newly created object

Exception - The account is not authorized to write to the table.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

modify

Modifies an existing object in a table.

 

Modifies an existing object in a table.

Parameters

  • itr - an iterator pointing to the object to be updated

  • payer - account name of the payer for the Storage usage of the updated row

  • updater - lambda function that updates the target object

Precondition

  • itr points to an existing element
  • payer is a valid account that is authorized to execute the action and be billed for storage usage.

Post Condition

  • The modified object is serialized, then replaces the existing object in the table.
  • Secondary indices are updated; the primary key of the updated object is not changed.
  • The payer is charged for the storage usage of the updated object.
  • If payer is the same as the existing payer, payer only pays for the usage difference between existing and updated object (and is refunded if this difference is negative).
  • If payer is different from the existing payer, the existing payer is refunded for the storage usage of the existing object.

Exceptions: If called with an invalid precondition, execution is aborted.

Example

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr != addresses.end(), "Address for account not found");
      addresses.modify( itr, account payer, [&]( auto& address ) {
        address.city = "San Luis Obispo";
        address.state = "CA";
      });
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

get

Retrieves an existing object from a table using its primary key.

 

Parameters

  • primary - Primary key value of the object

Returns

A constant reference to the object containing the specified primary key.

Exception - No object matches the given key

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto user = addresses.get(N(dan));
      eosio_assert(user.first_name == "Daniel", "Couldn't get him.");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

find

Search for an existing object in a table using its primary key.

 

Search for an existing object in a table using its primary key.

Parameters

  • primary - Primary key value of the object

Returns

An iterator to the found object which has a primary key equal to primary OR the end iterator of the referenced table if an object with primary key primary is not found.

find or get can actually be used to look up objects using secondary indexes by first using get_index and then calling find or get on that new multi_index instance.

Example:

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr != addresses.end(), "Couldn't get him.");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

erase

Remove an existing object from a table using its primary key.

 

Remove an existing object from a table using its primary key.

Parameters

  • itr - An iterator pointing to the object to be removed

Precondition

itr points to an existing element

Post Condition

  • The object is removed from the table and all associated storage is reclaimed.
  • Secondary indices associated with the table are updated.
  • The existing payer for storage usage of the object is refunded for the table and secondary indices usage of the removed object, and if the table and indices are removed, for the associated overhead.

Returns

For the signature with [const_iterator](#const_iterator), returns a pointer to the object following the removed object.

Exceptions

The object to be removed is not in the table. The action is not authorized to modify the table. The given iterator is invalid.

Example

#include 
using namespace eosio;
using namespace std;
class addressbook: contract {
  struct address {
     uint64_t account_name;
     string first_name;
     string last_name;
     string street;
     string city;
     string state;
     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
  };
  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;
    void myaction() {
      address_index addresses(_self, _self); // code, scope
      // add to table, first argument is account to bill for storage
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dan);
        address.first_name = "Daniel";
        address.last_name = "Larimer";
        address.street = "1 EOS Way";
        address.city = "Blacksburg";
        address.state = "VA";
      });
      auto itr = addresses.find(N(dan));
      eosio_assert(itr != addresses.end(), "Address for account not found");
      addresses.erase( itr );
      eosio_assert(itr != addresses.end(), "Address not erased properly");
    }
}
EOSIO_ABI( addressbook, (myaction) )
Suggest Edits

Serialize

Defines functions to serialize and deserialize object

 
Suggest Edits

EOSLIB_SERIALIZE

Defines serialization and deserialization for a class

 

Parameters

  • TYPE - the class to have its serialization and deserialization defined
  • MEMBERS - a sequence of member names to be serialized (field1)(field2)(field3)

Example

 EOSLIB_SERIALIZE( address, (account_name)(first_name)(last_name)(street)(city)(state) )
Suggest Edits

EOSLIB_SERIALIZE_DERIVED

Defines serialization and deserialization for a class which inherits from other classes that have their serialization and deserialization defined

 

Parameters

  • TYPE - the class to have its serialization and deserialization defined
  • BASE - a sequence of base class names (basea)(baseb)(basec)
  • MEMBERS - a sequence of member names. (field1)(field2)(field3)

Example

 EOSLIB_SERIALIZE_DERIVED( token, (asset), (amount)(symbol)(contract))
Suggest Edits

account_name

 

typedef uint64_t account_name

Suggest Edits

token_name

 

typedef uint64_t token_name

Suggest Edits

table_name

 

typedef uint64_t table_name

Suggest Edits

field_name

 

typedef fixed_string16 field_name

Suggest Edits

action_name

 

typedef uint64_t action_name

Suggest Edits

type_name

 

typedef fixed_string32 type_name

Suggest Edits

weight_type

 
typedef uint16_t weight_type;
Suggest Edits

symbol_name

 
  typedef uint64_t symbol_name;
Suggest Edits

N(base32 X)

Used to generate a compile time uint64_t from the base32 encoded string interpretation of X.

 
#define N(X) eosio::string_to_name(#X)
Suggest Edits

ALIGNED(checksum160)

Macro to align/overalign a type to ensure calls to intrinsics with pointers/references are properly aligned

 

160-bit hash

Suggest Edits

ALIGNED(checksum256)

Macro to align/overalign a type to ensure calls to intrinsics with pointers/references are properly aligned

 

256-bit hash

Suggest Edits

ALIGNED(checksum512)

Macro to align/overalign a type to ensure calls to intrinsics with pointers/references are properly aligned

 

512-bit hash

Suggest Edits

char_to_symbol(base32 c)

Converts a base32 symbol into its binary representation, used by string_to_name()

 

Parameters

  • c - Character to be converted

Returns

constexpr char - Converted character

Suggest Edits

string_to_name(base32 str)

Converts a base32 string to a uint64_t.

 

Converts a base32 string to a uint64_t. This is a constexpr so that this method can be used in template arguments as well.

Parameters

  • str - String representation of the name

Returns

constexpr uint64_t - 64-bit unsigned integer representation of the name

Example

void token::test( std::string user ){
....
    account_name eosio_name = eosio::string_to_name(user); // convert to EOSIO name from variable
    account_name eosiotoken_name = N(eosio.token); // convert to EOSIO name from fixed name
....
}