async def pw_absorb_rewards( self, wallet_id: str, fee: uint64 = uint64(0)) -> TransactionRecord: return TransactionRecord.from_json_dict( (await self.fetch("pw_absorb_rewards", { "wallet_id": wallet_id, "fee": fee }))["transaction"])
async def create_new_pool_wallet( self, target_puzzlehash: Optional[bytes32], pool_url: Optional[str], relative_lock_height: uint32, backup_host: str, mode: str, state: str, p2_singleton_delay_time: Optional[uint64] = None, p2_singleton_delayed_ph: Optional[bytes32] = None, ) -> TransactionRecord: request: Dict[str, Any] = { "wallet_type": "pool_wallet", "mode": mode, "host": backup_host, "initial_target_state": { "target_puzzle_hash": target_puzzlehash.hex() if target_puzzlehash else None, "relative_lock_height": relative_lock_height, "pool_url": pool_url, "state": state, }, } if p2_singleton_delay_time is not None: request["p2_singleton_delay_time"] = p2_singleton_delay_time if p2_singleton_delayed_ph is not None: request["p2_singleton_delayed_ph"] = p2_singleton_delayed_ph.hex() res = await self.fetch("create_new_wallet", request) return TransactionRecord.from_json_dict(res["transaction"])
async def pw_self_pool(self, wallet_id: str, fee: uint64) -> TransactionRecord: return TransactionRecord.from_json_dict( (await self.fetch("pw_self_pool", { "wallet_id": wallet_id, "fee": fee }))["transaction"])
async def send_transaction_multi( self, wallet_id: str, additions: List[Dict], coins: List[Coin] = None, fee: uint64 = uint64(0)) -> TransactionRecord: # Converts bytes to hex for puzzle hashes additions_hex = [{ "amount": ad["amount"], "puzzle_hash": ad["puzzle_hash"].hex() } for ad in additions] if coins is not None and len(coins) > 0: coins_json = [c.to_json_dict() for c in coins] response: Dict = await self.fetch( "send_transaction_multi", { "wallet_id": wallet_id, "additions": additions_hex, "coins": coins_json, "fee": fee }, ) else: response = await self.fetch("send_transaction_multi", { "wallet_id": wallet_id, "additions": additions_hex, "fee": fee }) return TransactionRecord.from_json_dict(response["transaction"])
async def get_transactions( self, wallet_id: str, start: int = None, end: int = None, sort_key: SortKey = None, reverse: bool = False, ) -> List[TransactionRecord]: request: Dict[str, Any] = {"wallet_id": wallet_id} if start is not None: request["start"] = start if end is not None: request["end"] = end if sort_key is not None: request["sort_key"] = sort_key.name request["reverse"] = reverse res = await self.fetch( "get_transactions", request, ) reverted_tx: List[TransactionRecord] = [] for modified_tx in res["transactions"]: # Server returns address instead of ph, but TransactionRecord requires ph modified_tx["to_puzzle_hash"] = decode_puzzle_hash( modified_tx["to_address"]).hex() del modified_tx["to_address"] reverted_tx.append(TransactionRecord.from_json_dict(modified_tx)) return reverted_tx
async def send_transaction( self, wallet_id: str, amount: uint64, address: str, fee: uint64 = uint64(0) ) -> TransactionRecord: res = await self.fetch( "send_transaction", {"wallet_id": wallet_id, "amount": amount, "address": address, "fee": fee}, ) return TransactionRecord.from_json_dict(res["transaction"])
async def pw_join_pool( self, wallet_id: str, target_puzzlehash: bytes32, pool_url: str, relative_lock_height: uint32 ) -> TransactionRecord: request = { "wallet_id": int(wallet_id), "target_puzzlehash": target_puzzlehash.hex(), "relative_lock_height": relative_lock_height, "pool_url": pool_url, } return TransactionRecord.from_json_dict((await self.fetch("pw_join_pool", request))["transaction"])
async def get_transaction(self, wallet_id: str, transaction_id: bytes32) -> TransactionRecord: res = await self.fetch( "get_transaction", { "walled_id": wallet_id, "transaction_id": transaction_id.hex() }, ) return TransactionRecord.from_json_dict(res["transaction"])
async def pw_status( self, wallet_id: str) -> Tuple[PoolWalletInfo, List[TransactionRecord]]: json_dict = await self.fetch("pw_status", {"wallet_id": wallet_id}) return ( PoolWalletInfo.from_json_dict(json_dict["state"]), [ TransactionRecord.from_json_dict(tr) for tr in json_dict["unconfirmed_transactions"] ], )
async def get_transactions( self, wallet_id: str, ) -> List[TransactionRecord]: res = await self.fetch( "get_transactions", {"wallet_id": wallet_id}, ) reverted_tx: List[TransactionRecord] = [] for modified_tx in res["transactions"]: # Server returns address instead of ph, but TransactionRecord requires ph modified_tx["to_puzzle_hash"] = decode_puzzle_hash(modified_tx["to_address"]).hex() del modified_tx["to_address"] reverted_tx.append(TransactionRecord.from_json_dict(modified_tx)) return reverted_tx