ain.db.ref module

class ain.db.ref.Reference(ain: Ain, path: str = None)

Bases: object

Class that creates a reference to a path in the AIN Database.

static buildGetRequest(type: Literal['GET_VALUE', 'GET_RULE', 'GET_OWNER', 'GET_FUNCTION'], ref: str, options: GetOptions = None) dict

Builds a get request.

Parameters:
  • type (GetOperationType) – The type of get operation.

  • ref (str) – The path that you want to make transaction.

  • options (GetOptions, Optional) – The options for this transaction. Defaults to no options.

Returns:

The builded get request.

Return type:

dict

async decrementValue(transactionInput: ValueOnlyTransactionInput, isDryrun=False) Any

Decrements the value.

Parameters:
Returns:

The result of the transaction.

async deleteValue(transactionInput: ValueOnlyTransactionInput = None, isDryrun=False) Any

Deletes the value.

Parameters:
  • transactionInput (ValueOnlyTransactionInput) – The transaction input object. Any value given will be overwritten with null.

  • isDryrun (bool) – Dryrun option.

Returns:

The result of the transaction.

async evalOwner(params: EvalOwnerInput) Any

Evals the owner evaluation result.

Parameters:

params (EvalOwnerInput) – The eval owner input object.

Returns:

The owner evaluation result.

async evalRule(params: EvalRuleInput) Any

Evals the rule evaluation result.

Parameters:

params (EvalRuleInput) – The eval rule input object.

Returns:

The result of the evaluation. True, if the params satisfy the write rule, False, if not.

static extendPath(basePath: str = None, extension: str = None) str

Extends the path.

Parameters:
  • basePath (str, Optional) – The base path that you want.

  • extension (str, Optional) – The extension that you want to extend under the base path.

Returns:

The extended basePath, by the extension.

Return type:

str

static extendSetMultiTransactionInput(input: SetMultiTransactionInput, ref: str, type: Literal['SET'] = 'SET') TransactionInput

Extends the transaction input with an appropriate type and op_list.

Parameters:
  • input (SetMultiTransactionInput) – The transaction input object.

  • ref (str) – The path that you want to make transaction.

  • type (SetMultiOperationType) – The type of set operations.

Returns:

The decorated transaction input.

Return type:

TransactionInput

static extendSetTransactionInput(input: ValueOnlyTransactionInput, ref: str, type: Literal['SET_VALUE', 'INC_VALUE', 'DEC_VALUE', 'SET_RULE', 'SET_OWNER', 'SET_FUNCTION'], isGlobal: bool) TransactionInput

Extends the transaction input with an appropriate type, ref and value.

Parameters:
  • input (ValueOnlyTransactionInput) – The transaction input object.

  • ref (str) – The path that you want to make transaction.

  • type (SetOperationType) – The type of set operation.

Returns:

The decorated transaction input.

Return type:

TransactionInput

async get(gets: List[GetOperation]) Any

Gets a value, write rule, owner rule, or function hash at multiple paths.

Parameters:

gets (List[GetOperation]) – The array of the get requests. Could be any one from “VALUE”, “RULE”, “OWNER”, “FUNC” or a combination of them as an array.

Returns:

The value, write rule, owner rule, or function hash at multiple paths.

async getFunction(path: str = None, options: GetOptions = None) Any

Gets a function config at the path.

Parameters:
  • path (str, Optional) – The path that you want to extend under the base path. If path is None, no extending. Defaults to None.

  • options (GetOptions, Optional) – The options for this transaction. Defaults to no options.

Returns:

The function config at the path.

async getOwner(path: str = None, options: GetOptions = None) Any

Gets an owner config at the path.

Parameters:
  • path (str, Optional) – The path that you want to extend under the base path. If path is None, no extending. Defaults to None.

  • options (GetOptions, Optional) – The options for this transaction. Defaults to no options.

Returns:

The owner config at the path.

async getProofHash(params: StateInfoInput = None) Any

Fetches the proof hash of a global blockchain state path.

Parameters:

params (StateInfoInput) – The state info input object.

Returns:

The return value of the blockchain API.

async getRule(path: str = None, options: GetOptions = None) Any

Gets a rule at the path.

Parameters:
  • path (str, Optional) – The path that you want to extend under the base path. If path is None, no extending. Defaults to None.

  • options (GetOptions, Optional) – The options for this transaction. Defaults to no options.

Returns:

The rule at the path.

async getStateInfo(params: StateInfoInput = None) Any

Fetches the state information of a global blockchain state path.

Parameters:

params (StateInfoInput) – The state info input object.

Returns:

The return value of the blockchain API.

async getStateProof(params: StateInfoInput = None) Any

Fetches the state proof of a global blockchain state path.

Parameters:

params (StateInfoInput) – The state info input object.

Returns:

The return value of the blockchain API.

async getValue(path: str = None, options: GetOptions = None) Any

Gets a value at the path.

Parameters:
  • path (str, Optional) – The path that you want to extend under the base path. If path is None, no extending. Defaults to None.

  • options (GetOptions, Optional) – The options for this transaction. Defaults to no options.

Returns:

The value at the path.

async incrementValue(transactionInput: ValueOnlyTransactionInput, isDryrun=False) Any

Increments the value.

Parameters:
Returns:

The result of the transaction.

async matchFunction(params: MatchInput = None) Any

Matches the function configs that are related to the input ref.

Parameters:

params (MatchInput) – The match input object.

Returns:

The function configs that are related to the input ref.

async matchOwner(params: MatchInput = None) Any

Matches the owner configs that are related to the input ref.

Parameters:

params (MatchInput) – The match input object.

Returns:

The owner configs that are related to the input ref.

async matchRule(params: MatchInput = None) Any

Matches the rule configs that are related to the input ref.

Parameters:

params (MatchInput) – The match input object.

Returns:

The rule configs that are related to the input ref.

push() Reference

Creates a key for a new child of base path virtually. So doesn’t set any values on the AIN Blockchain.

Returns:

The instance of Reference of a new child.

Return type:

Reference

async pushValue(value: Any = None) Any

Sets the value at a new child of base path.

Parameters:

value (Any, Optional) – The value that you want to set. Defaults to None.

Returns:

The result of the transaction.

static sanitizeRef(ref: str = None) str

Sanitizes the path.

Parameters:

ref (str) – A path that you want to sanitize.

Returns:

A sanitized ref. It should have a slash at the beginning and no slash at the end.

Return type:

str

async set(transactionInput: SetMultiTransactionInput, isDryrun=False) Any

Processes the multiple set operations.

Parameters:
Returns:

The result of the transaction.

async setFunction(transactionInput: ValueOnlyTransactionInput, isDryrun=False) Any

Sets the function config.

Parameters:
Returns:

The result of the transaction.

setIsGlobal(isGlobal: bool)

Sets a global reference using flag.

Parameters:

isGlobal (bool) – The global reference using flag.

async setOwner(transactionInput: ValueOnlyTransactionInput, isDryrun=False) Any

Sets the owner rule.

Parameters:
Returns:

The result of the transaction.

async setRule(transactionInput: ValueOnlyTransactionInput, isDryrun=False) Any

Sets the write rule.

Parameters:
Returns:

The result of the transaction.

async setValue(transactionInput: ValueOnlyTransactionInput, isDryrun=False) Any

Sets the value.

Parameters:
Returns:

The result of the transaction.

property key: str | None

The key of this reference.

property path: str

The base path of this reference.