viz.viz

Module Contents

log
class Client

Bases: graphenecommon.chain.AbstractGrapheneChain

Inheritance diagram of viz.viz.Client
private-bases

Blockchain network client.

param str node

Node to connect to

param str rpcuser

RPC user (optional)

param str rpcpassword

RPC password (optional)

param bool nobroadcast

Do not broadcast a transaction! (optional)

param bool debug

Enable Debugging (optional)

param array,dict,string keys

Predefine the wif keys to shortcut the wallet database (optional)

param bool offline

Boolean to prevent connecting to network (defaults to False) (optional)

param int expiration

Delay in seconds until transactions are supposed to expire (optional)

param bool blocking

Wait for broadcasted transactions to be included in a block and return full transaction. Blocking is checked inside broadcast() (Default: False), (optional)

param bool bundle

Do not broadcast transactions right away, but allow to bundle operations (optional)

Three wallet operation modes are possible:

  • Wallet Database: Here, the libs load the keys from the locally stored wallet SQLite database (see storage.py). To use this mode, simply call Client() without the keys parameter

  • Providing Keys: Here, you can provide the keys for your accounts manually. All you need to do is add the wif keys for the accounts you want to use as a simple array using the keys parameter to Client().

  • Force keys: This more is for advanced users and requires that you know what you are doing. Here, the keys parameter is a dictionary that overwrite the active, master, or memo keys for any account. This mode is only used for foreign signatures!

The purpose of this class it to simplify interaction with blockchain by providing high-level methods instead of forcing user to use RPC methods directly.

The idea is to have a class that allows to do this:

from viz import Client
viz = Client()
print(viz.info())
define_classes(self)
new_proposal(self, title: str, memo: str = '', parent: Optional[TransactionBuilder] = None, expiration_time: int = 2 * 24 * 60 * 60, review_period_time: Optional[int] = None, account: str = None, **kwargs: Any)

Create a new proposal.

Proposal is a way to propose some transaction to another account. Primary usecase is a multisig account which requires several members approval to perform an operation.

Parameters
  • title (str) – title of proposed transaction

  • memo (str) – may be a description of the proposal

  • parent (TransactionBuilder) – TransactionBuilder instance to add proposal to

  • expiration_time (int) – maximum time allowed for transaction

  • review_period_time (int) – time to make a decision of the transaction participants

  • account (str) – author of proposed transaction

Example usage:

from viz import Client
viz = Client()
proposal = viz.new_proposal('title', 'test proposal', account='alice')
viz.transfer("null", 1, "VIZ", memo="test transfer proposal", account=default_account, append_to=proposal)
proposal.broadcast()
proposal_update(self, author: str, title: str, approver: Union[str, list] = None, keys: Union[str, list] = None, permission: str = 'regular', approve: bool = True, account: str = None)

Update proposal (approve or disapprove)

Parameters
  • author (str) – author of proposed transaction

  • title (str) – title of proposed transaction

  • list approver (str,) – account(s) for approvals, default is account field

  • keys (str) – public key(s) used for multisig accounts (key approval)

  • permission (str) – the required permission type for signing

  • approve (str) – True = approve, False = disapprove

  • account (str) – the account that authorizes the operation

transfer(self, to: str, amount: float, asset: str, memo: str = '', account: Optional[str] = None, **kwargs: Any)

Transfer an asset to another account.

Parameters
  • to (str) – Recipient

  • amount (float) – Amount to transfer

  • asset (str) – Asset to transfer

  • memo (str) – (optional) Memo, may begin with # for encrypted messaging

  • account (str) – (optional) the source account for the transfer if not default_account

award(self, receiver: str, energy: float, memo: str = '', beneficiaries: Optional[List[Dict[str, Union[str, int]]]] = None, account: str = None, **kwargs: Any)

Award someone.

Parameters
  • receiver (str) – account name of award receiver

  • energy (float) – energy as 0-100%

  • memo (str) – optional comment

  • beneficiaries (list) – list of dicts, example [{'account': 'vvk', 'weight': 50}]

  • account (str) – initiator account name

custom(self, id_: str, json: Union[Dict, List], required_active_auths: Optional[List[str]] = None, required_regular_auths: Optional[List[str]] = None)

Create a custom operation.

Parameters
  • id (str) – identifier for the custom (max length 32 bytes)

  • json (dict,list) – the json data to put into the custom operation

  • required_active_auths (list) – (optional) require signatures from these active auths to make this operation valid

  • required_regular_auths (list) – (optional) require signatures from these regular auths

withdraw_vesting(self, amount: float, account: str = None)

Withdraw SHARES from the vesting account.

Parameters
  • amount (float) – number of SHARES to withdraw over a period

  • account (str) – (optional) the source account for the transfer if not default_account

transfer_to_vesting(self, amount: float, to: str = None, account: str = None)

Vest free VIZ into vesting.

Parameters
  • amount (float) – number of VIZ to vest

  • to (str) – (optional) the source account for the transfer if not default_account

  • account (str) – (optional) the source account for the transfer if not default_account

set_withdraw_vesting_route(self, to: str, percentage: float = 100, account: str = None, auto_vest: bool = False)

Set up a vesting withdraw route. When vesting shares are withdrawn, they will be routed to these accounts based on the specified weights.

To obtain existing withdraw routes, use get_withdraw_vesting_routes()

a = Account('vvk', blockchain_instance=viz)
pprint(a.get_withdraw_routes())
Parameters
  • to (str) – Recipient of the vesting withdrawal

  • percentage (float) – The percent of the withdraw to go to the ‘to’ account.

  • account (str) – (optional) the vesting account

  • auto_vest (bool) – Set to true if the from account should receive the SHARES as SHARES, or false if it should receive them as CORE. (defaults to False)

get_withdraw_vesting_routes(self, account: str, **kwargs: str)

Get vesting withdraw route for an account.

This is a shortcut for viz.account.Account.get_withdraw_routes().

Parameters

account (str) – account name

Returns

list with routes

create_account(self, account_name: str, json_meta: Optional[Dict[str, Any]] = None, password: str = None, master_key: str = None, active_key: str = None, regular_key: str = None, memo_key: str = None, additional_master_keys: Optional[List[str]] = None, additional_active_keys: Optional[List[str]] = None, additional_regular_keys: Optional[List[str]] = None, additional_master_accounts: Optional[List[str]] = None, additional_active_accounts: Optional[List[str]] = None, additional_regular_accounts: Optional[List[str]] = None, store_keys: bool = True, fee: float = 0, delegation: float = 0, creator: str = None, referrer: str = '')

Create new account.

The brainkey/password can be used to recover all generated keys (see vizbase.account for more details.

By default, this call will use default_account to register a new name account_name with all keys being derived from a new brain key that will be returned. The corresponding keys will automatically be installed in the wallet.

Note

Account creations cost a fee that is defined by the network. If you create an account, you will need to pay for that fee!

You can partially pay that fee by delegating SHARES.

Warning

Don’t call this method unless you know what you are doing! Be sure to understand what this method does and where to find the private keys for your account.

Note

Please note that this imports private keys (if password is present) into the wallet by default.

Parameters
  • account_name (str) – (required) new account name

  • json_meta (dict) – Optional meta data for the account

  • password (str) – Alternatively to providing keys, one can provide a password from which the keys will be derived

  • master_key (str) – Main master key

  • active_key (str) – Main active key

  • regular_key (str) – Main regular key

  • memo_key (str) – Main memo_key

  • additional_master_keys (list) – Additional master public keys

  • additional_active_keys (list) – Additional active public keys

  • additional_regular_keys (list) – Additional regular public keys

  • additional_master_accounts (list) – Additional master account names

  • additional_active_accounts (list) – Additional active account names

  • additional_regular_accounts (list) – Additional regular account names

  • store_keys (bool) – Store new keys in the wallet (default: True)

  • fee (float) – (Optional) If set, creator pay a fee of this amount, and delegate the rest with SHARES (calculated automatically).

  • delegation (float) – amount of SHARES to be delegated to a new account

  • creator (str) – which account should pay the registration fee (defaults to default_account)

  • referrer (str) – account who will be set as referrer, defaults to creator

Raises

AccountExistsException – if the account already exists on the blockchain

_store_keys(self, *args)

Store private keys to local storage.