Esempio n. 1
0
 def lock_wallet(self, wallet_name):
     """
     Locks an existing wallet of the given name.
         :param wallet_name(string): name of the wallet to create
     """
     url = self.base_url + WALLET_API_ENUM.get('LOCK_WALLET')
     return make_post_request(url, json.dumps(wallet_name))
Esempio n. 2
0
 def create_wallet(self, wallet_name):
     """
     Creates a new wallet with the given name.
         :param wallet_name(string): name of the wallet to create
     """
     url = self.base_url + WALLET_API_ENUM.get('CREATE_WALLET')
     return make_post_request(url, json.dumps(wallet_name))
Esempio n. 3
0
 def import_key(self, wallet_name, key):
     """
     Unlocks an existing wallet of the given name.
         :param wallet_name(string): name of the wallet to create
         :param key(string): key to import in the wallet. It will be a private key
     """
     url = self.base_url + WALLET_API_ENUM.get('IMPORT_KEY')
     payload = [wallet_name, key]
     return make_post_request(url, json.dumps(payload))
Esempio n. 4
0
 def unlock_wallet(self, wallet_name, password):
     """
     Unlocks an existing wallet of the given name.
         :param wallet_name(string): name of the wallet to create
         :param password(string): password for the given wallet
     """
     url = self.base_url + WALLET_API_ENUM.get('UNLOCK_WALLET')
     payload = [wallet_name, password]
     return make_post_request(url, json.dumps(payload))
Esempio n. 5
0
 def sign_transaction(self, transaction, keys, _id=""):
     """
     Signs a transaction.
         :param transaction: transaction to be signed
         :param keys: public keys to cross check the transaction
         :param id: ID for the chain this transaction is targeted towards.
     """
     url = self.base_url + WALLET_API_ENUM.get('SIGN_TRANSACTION')
     payload = [transaction, keys, _id]
     return make_post_request(url, json.dumps(payload))
Esempio n. 6
0
 def get_block(self, block_num_or_id):
     """
     Returns an object containing various details about a specific block on the blockchain.
         :param block_num_or_id: id or block number
     """
     url = self.base_url + CHAIN_API_ENUM.get('GET_BLOCK')
     payload = {
         "block_num_or_id": str(block_num_or_id)
     }
     return make_post_request(url, json.dumps(payload))
Esempio n. 7
0
 def get_account(self, account_name):
     """
     Returns an object containing various details about a specific account on the blockchain.
         :param account_name: name of account in blockchain
     """
     url = self.base_url + CHAIN_API_ENUM.get('GET_ACCOUNT')
     payload = {
         "account_name": account_name
     }
     return make_post_request(url, json.dumps(payload))
Esempio n. 8
0
 def push_transaction(self, transaction, signatures):
     """
     Applies a transaction in json format to the blockchain
         :param transaction: transaction to push
     """
     url = self.base_url + CHAIN_API_ENUM.get('PUSH_TRANSACTION')
     payload = {
         "compression": "none",
         "transaction": transaction,
         "signatures": signatures
     }
     return make_post_request(url, json.dumps(payload))
Esempio n. 9
0
 def get_required_keys(self, transaction, available_keys):
     """
     Returns the required keys needed to sign a transaction.
         :param transaction: transaction object
         :param available_keys: available public keys
     """
     url = self.base_url + CHAIN_API_ENUM.get('GET_REQUIRED_KEYS')
     payload = {
         "transaction": transaction,
         "available_keys": available_keys
     }
     return make_post_request(url, json.dumps(payload))
Esempio n. 10
0
 def abi_json_to_bin(self, account_name, action, **kwargs):
     """
     Serializes json to binary hex.
     The resulting binary hex is usually used for the data field in push_transaction.
         :param account_name: name of acocunt
         :param action: name of action (function defined in contract)
         :param kwargs: action parameters
     """
     url = self.base_url + CHAIN_API_ENUM.get('ABI_JSON_TO_BIN')
     payload = {
         "code": account_name,
         "action": action,
         "args": kwargs
     }
     return make_post_request(url, json.dumps(payload))
Esempio n. 11
0
 def get_info(self):
     """
     Returns an object containing various details about the blockchain.
     """
     url = self.base_url + CHAIN_API_ENUM.get('GET_INFO')
     return make_post_request(url)