def changekey(self, name: str, newaddr: str, memo: str = ""): oldpubkey = privkey_to_pubkey(self._privkey) oldaddr = pubkey_to_address(oldpubkey) self._memo = memo self._get_account_info(oldaddr) url = "/".join([self._host, "nickname/change"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "from": oldaddr, }, "name": name, "new_address": newaddr, } resp = self._put_json(url, json_param=params) if resp.status_code != 200: print(resp.text) raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def claim(self, reward_or_commission: bool, fare: int, memo: str = ""): pubkey = privkey_to_pubkey(self._privkey) address = pubkey_to_address(pubkey) self._memo = memo self._get_account_info(address) url = "/".join([self._host, "hdac/claim"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "from": address, }, "reward_or_commission": reward_or_commission, "fee": str(fare), } resp = self._post_json(url, json_param=params) if resp.status_code != 200: print(resp.text) raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def _get_pushable_tx(self) -> str: pubkey = privkey_to_pubkey(self._privkey) base64_pubkey = base64.b64encode(bytes.fromhex(pubkey)).decode("utf-8") pushable_tx = { "tx": { "msg": self._msgs, "fee": { "gas": str(self._gas_price), "amount": [], }, "memo": self._memo, "signatures": [{ "signature": self._sign(), "pub_key": { "type": "tendermint/PubKeySecp256k1", "value": base64_pubkey }, "account_number": str(self._account_num), "sequence": str(self._sequence), }], }, "mode": self._sync_mode, } return pushable_tx
def set_nick(self, name: str, gas_price: int, memo: str = ""): pubkey = privkey_to_pubkey(self._privkey) address = pubkey_to_address(pubkey) self._gas_price = gas_price self._memo = memo self._get_account_info(address) url = "/".join([self._host, "nickname/new"]) params = { "base_req": { "chain_id": self._chain_id, "gas": str(gas_price), "memo": memo, "from": address, }, "nickname": name, } resp = self._post_json(url, json_param=params) if resp.status_code != 200: print(resp.text) raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def unvote(self, target_contract_address: str, amount: int, fare: int, memo: str = ""): pubkey = privkey_to_pubkey(self._privkey) address = pubkey_to_address(pubkey) self._memo = memo self._get_account_info(address) url = "/".join([self._host, "hdac/unvote"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "from": address, }, "target_contract_address": target_contract_address, "amount": str(amount), "fee": str(fare), } resp = self._post_json(url, json_param=params) if resp.status_code != 200: print(resp.text) raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def execute_contract( self, execution_type: str, token_contract_address_or_key_name: str, base64_encoded_binary: str, args: str, gas_price: int, fee: int, memo: str = "", ): sender_pubkey = privkey_to_pubkey(self._privkey) sender_address = pubkey_to_address(sender_pubkey) self._gas_price = gas_price self._memo = memo self._get_account_info(sender_address) if execution_type == "wasm": token_contract_address_or_key_name = "" else: # hash | uref | name base64_encoded_binary = "" url = "/".join([self._host, "contract"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "gas": str(gas_price), "from": sender_address, }, "type": execution_type, "token_contract_address_or_key_name": token_contract_address_or_key_name, "base64_encoded_binary": base64_encoded_binary, "args": args, "fee": str(fee), } resp = self._post_json(url, json_param=params) if resp.status_code != 200: raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def create_validator( self, validator_address: str, cons_pub_key: str, moniker: str, gas_price: int, identity: str = "", website: str = "", details: str = "", memo: str = "", ): pubkey = privkey_to_pubkey(self._privkey) address = pubkey_to_address(pubkey) self._gas_price = gas_price self._memo = memo self._get_account_info(address) url = "/".join([self._host, "hdac/validators"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "gas": str(gas_price), "from": validator_address, }, "cons_pub_key": cons_pub_key, "description": { "moniker": moniker, "identity": identity, "website": website, "details": details, }, } resp = self._post_json(url, json_param=params) if resp.status_code != 200: print(resp.text) raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def transfer( self, recipient_address: str, amount: int, fare: int, memo: str = "", batch_mode: bool = False, ): sender_pubkey = privkey_to_pubkey(self._privkey) sender_address = pubkey_to_address(sender_pubkey) self._memo = memo self._get_account_info(sender_address) params = { "type": "friday/StdTx", "value": { "msg": [{ "type": "executionengine/Transfer", "value": { "contract_address": "system:transfer", "from_address": sender_address, "to_address": recipient_address, "amount": str(int(amount * (10**18))), "fee": str(int(fare * (10**18))) } }], "fee": { "amount": [], "gas": "100000000" }, "signatures": "", "memo": memo } } msgs = params.get("value").get("msg") self._msgs.extend(msgs) if batch_mode == False: # 1 tx 1 msg return self._send_tx()
def transfer( self, recipient_address: str, amount: int, gas_price: int, fee: int, memo: str = "", ): sender_pubkey = privkey_to_pubkey(self._privkey) sender_address = pubkey_to_address(sender_pubkey) self._gas_price = gas_price self._memo = memo self._get_account_info(sender_address) url = "/".join([self._host, "hdac/transfer"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "gas": str(gas_price), "from": sender_address, }, "fee": str(fee), "recipient_address_or_nickname": recipient_address, "amount": str(amount), } resp = self._post_json(url, json_param=params) if resp.status_code != 200: raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: print(resp.text) raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()
def redelegate(self, src_validator_address: str, dest_validator_address: str, amount: int, gas_price: int, fee: int, memo: str = ""): pubkey = privkey_to_pubkey(self._privkey) address = pubkey_to_address(pubkey) self._gas_price = gas_price self._memo = memo self._get_account_info(address) url = "/".join([self._host, "hdac/redelegate"]) params = { "base_req": { "chain_id": self._chain_id, "memo": memo, "gas": str(gas_price), "from": address, }, "src_validator_address": src_validator_address, "dest_validator_address": dest_validator_address, "amount": str(amount), "fee": str(fee), } resp = self._post_json(url, json_param=params) if resp.status_code != 200: raise BadRequestException value = resp.json().get("value") msgs = value.get("msg") if len(msgs) == 0: raise EmptyMsgException self._msgs.extend(msgs) return self._send_tx()