def ClaimGas(wallet, require_password=True): unclaimed_coins = wallet.GetUnclaimedCoins() unclaimed_coin_refs = [coin.Reference for coin in unclaimed_coins] if len(unclaimed_coin_refs) == 0: print("no claims to process") return False available_bonus = Blockchain.Default().CalculateBonusIgnoreClaimed( unclaimed_coin_refs) if available_bonus == Fixed8.Zero(): print("No gas to claim") return False claim_tx = ClaimTransaction() claim_tx.Claims = unclaimed_coin_refs claim_tx.Attributes = [] claim_tx.inputs = [] claim_tx.outputs = [ TransactionOutput(AssetId=Blockchain.SystemCoin().Hash, Value=available_bonus, script_hash=wallet.GetChangeAddress()) ] context = ContractParametersContext(claim_tx) wallet.Sign(context) print("\n---------------------------------------------------------------") print("Will make claim for %s GAS" % available_bonus.ToString()) print( "------------------------------------------------------------------\n") if require_password: print("Enter your password to complete this claim") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") return if context.Completed: claim_tx.scripts = context.GetScripts() wallet.SaveTransaction(claim_tx) relayed = NodeLeader.Instance().Relay(claim_tx) if relayed: print("Relayed Tx: %s " % claim_tx.Hash.ToString()) else: print("Could not relay tx %s " % claim_tx.Hash.ToString()) return claim_tx, relayed else: print("could not sign tx") return None, False
def ClaimGas(wallet, require_password=True, args=None): unclaimed_coins = wallet.GetUnclaimedCoins() unclaimed_coin_refs = [coin.Reference for coin in unclaimed_coins] if len(unclaimed_coin_refs) == 0: print("no claims to process") return False available_bonus = Blockchain.Default().CalculateBonusIgnoreClaimed( unclaimed_coin_refs) if available_bonus == Fixed8.Zero(): print("No gas to claim") return False claim_tx = ClaimTransaction() claim_tx.Claims = unclaimed_coin_refs claim_tx.Attributes = [] claim_tx.inputs = [] script_hash = wallet.GetChangeAddress() # the following can be used to claim gas that is in an imported contract_addr # example, wallet claim --from-addr={smart contract addr} if args: params, from_addr_str = get_from_addr(args) if from_addr_str: script_hash = wallet.ToScriptHash(from_addr_str) standard_contract = wallet.GetStandardAddress() claim_tx.Attributes = [ TransactionAttribute(usage=TransactionAttributeUsage.Script, data=standard_contract.Data) ] claim_tx.outputs = [ TransactionOutput(AssetId=Blockchain.SystemCoin().Hash, Value=available_bonus, script_hash=script_hash) ] context = ContractParametersContext(claim_tx) wallet.Sign(context) print("\n---------------------------------------------------------------") print("Will make claim for %s GAS" % available_bonus.ToString()) print( "------------------------------------------------------------------\n") if require_password: print("Enter your password to complete this claim") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") return if context.Completed: claim_tx.scripts = context.GetScripts() print("claim tx: %s " % json.dumps(claim_tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(claim_tx) if relayed: print("Relayed Tx: %s " % claim_tx.Hash.ToString()) wallet.SaveTransaction(claim_tx) else: print("Could not relay tx %s " % claim_tx.Hash.ToString()) return claim_tx, relayed else: print("could not sign tx") return None, False
def ClaimGas(wallet, require_password=True, args=None): """ Args: wallet: require_password: args: Returns: (claim transaction, relayed status) if successful: (tx, True) if unsuccessful: (None, False) """ if args: params, from_addr_str = get_from_addr(args) else: params = None from_addr_str = None unclaimed_coins = wallet.GetUnclaimedCoins() unclaimed_count = len(unclaimed_coins) if unclaimed_count == 0: print("no claims to process") return None, False max_coins_per_claim = None if params: max_coins_per_claim = get_arg(params, 0, convert_to_int=True) if not max_coins_per_claim: print("max_coins_to_claim must be an integer") return None, False if max_coins_per_claim <= 0: print("max_coins_to_claim must be greater than zero") return None, False if max_coins_per_claim and unclaimed_count > max_coins_per_claim: unclaimed_coins = unclaimed_coins[:max_coins_per_claim] unclaimed_coin_refs = [coin.Reference for coin in unclaimed_coins] available_bonus = Blockchain.Default().CalculateBonusIgnoreClaimed( unclaimed_coin_refs) if available_bonus == Fixed8.Zero(): print("No gas to claim") return None, False claim_tx = ClaimTransaction() claim_tx.Claims = unclaimed_coin_refs claim_tx.Attributes = [] claim_tx.inputs = [] script_hash = wallet.GetChangeAddress() # the following can be used to claim gas that is in an imported contract_addr # example, wallet claim --from-addr={smart contract addr} if from_addr_str: script_hash = wallet.ToScriptHash(from_addr_str) standard_contract = wallet.GetStandardAddress() claim_tx.Attributes = [ TransactionAttribute(usage=TransactionAttributeUsage.Script, data=standard_contract.Data) ] claim_tx.outputs = [ TransactionOutput(AssetId=Blockchain.SystemCoin().Hash, Value=available_bonus, script_hash=script_hash) ] context = ContractParametersContext(claim_tx) wallet.Sign(context) print("\n---------------------------------------------------------------") print("Will make claim for %s GAS" % available_bonus.ToString()) if max_coins_per_claim and unclaimed_count > max_coins_per_claim: print( "NOTE: You are claiming GAS on %s unclaimed coins. %s additional claim transactions will be required to claim all available GAS." % (max_coins_per_claim, math.floor(unclaimed_count / max_coins_per_claim))) print( "------------------------------------------------------------------\n") if require_password: print("Enter your password to complete this claim") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") return None, False if context.Completed: claim_tx.scripts = context.GetScripts() print("claim tx: %s " % json.dumps(claim_tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(claim_tx) if relayed: print("Relayed Tx: %s " % claim_tx.Hash.ToString()) wallet.SaveTransaction(claim_tx) else: print("Could not relay tx %s " % claim_tx.Hash.ToString()) return claim_tx, relayed else: print("could not sign tx") return None, False
def ClaimGas(wallet, require_password=True, from_addr_str=None, to_addr_str=None): """ Args: wallet: require_password: from_addr_str: Returns: (claim transaction, relayed status) if successful: (tx, True) if unsuccessful: (None, False) """ if not wallet: print("Please open a wallet") return None, False unclaimed_coins = wallet.GetUnclaimedCoins() unclaimed_count = len(unclaimed_coins) if unclaimed_count == 0: print("No claims to process") return None, False unclaimed_coin_refs = [coin.Reference for coin in unclaimed_coins] available_bonus = Blockchain.Default().CalculateBonusIgnoreClaimed( unclaimed_coin_refs) if available_bonus == Fixed8.Zero(): print("No gas to claim") return None, False claim_tx = ClaimTransaction() claim_tx.Claims = unclaimed_coin_refs claim_tx.Attributes = [] claim_tx.inputs = [] script_hash = wallet.GetChangeAddress() # the following can be used to claim gas that is in an imported contract_addr # example, wallet claim --from-addr={smart contract addr} if from_addr_str: script_hash = None script_hash = PromptUtils.lookup_addr_str(wallet, from_addr_str) if script_hash is None: logger.debug("invalid source address") return None, False standard_contract = wallet.GetStandardAddress() claim_tx.Attributes = [ TransactionAttribute(usage=TransactionAttributeUsage.Script, data=standard_contract.Data) ] if to_addr_str: script_hash = None script_hash = PromptUtils.lookup_addr_str(wallet, to_addr_str) if script_hash is None: logger.debug("invalid destination address") return None, False claim_tx.outputs = [ TransactionOutput(AssetId=Blockchain.SystemCoin().Hash, Value=available_bonus, script_hash=script_hash) ] context = ContractParametersContext(claim_tx) wallet.Sign(context) print("\n---------------------------------------------------------------") print(f"Will make claim for {available_bonus.ToString()} GAS") print( "------------------------------------------------------------------\n") if require_password: print("Enter your password to complete this claim") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("Incorrect password") return None, False if context.Completed: claim_tx.scripts = context.GetScripts() print("claim tx: %s " % json.dumps(claim_tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(claim_tx) if relayed: print("Relayed Tx: %s " % claim_tx.Hash.ToString()) wallet.SaveTransaction(claim_tx) else: print("Could not relay tx %s " % claim_tx.Hash.ToString()) return claim_tx, relayed else: print("could not sign tx") return None, False
def ClaimGas(wallet, require_password=True, args=None): unclaimed_coins = wallet.GetUnclaimedCoins() unclaimed_coin_refs = [coin.Reference for coin in unclaimed_coins] if len(unclaimed_coin_refs) == 0: print("no claims to process") return False available_bonus = Blockchain.Default().CalculateBonusIgnoreClaimed(unclaimed_coin_refs) if available_bonus == Fixed8.Zero(): print("No gas to claim") return False claim_tx = ClaimTransaction() claim_tx.Claims = unclaimed_coin_refs claim_tx.Attributes = [] claim_tx.inputs = [] script_hash = wallet.GetChangeAddress() # the following can be used to claim gas that is in an imported contract_addr # example, wallet claim --from-addr={smart contract addr} if args: params, from_addr_str = get_from_addr(args) if from_addr_str: script_hash = wallet.ToScriptHash(from_addr_str) standard_contract = wallet.GetStandardAddress() claim_tx.Attributes = [TransactionAttribute(usage=TransactionAttributeUsage.Script, data=standard_contract.Data)] claim_tx.outputs = [ TransactionOutput(AssetId=Blockchain.SystemCoin().Hash, Value=available_bonus, script_hash=script_hash) ] context = ContractParametersContext(claim_tx) wallet.Sign(context) print("\n---------------------------------------------------------------") print("Will make claim for %s GAS" % available_bonus.ToString()) print("------------------------------------------------------------------\n") if require_password: print("Enter your password to complete this claim") passwd = prompt("[Password]> ", is_password=True) if not wallet.ValidatePassword(passwd): print("incorrect password") return if context.Completed: claim_tx.scripts = context.GetScripts() print("claim tx: %s " % json.dumps(claim_tx.ToJson(), indent=4)) relayed = NodeLeader.Instance().Relay(claim_tx) if relayed: print("Relayed Tx: %s " % claim_tx.Hash.ToString()) wallet.SaveTransaction(claim_tx) else: print("Could not relay tx %s " % claim_tx.Hash.ToString()) return claim_tx, relayed else: print("could not sign tx") return None, False