def spawn(self, verify: bool = False, sign: bool = False, send: bool = False, locktime: int = 0, **kwargs): '''prepare deck spawn transaction''' deck = self.__new(**kwargs) spawn = pa.deck_spawn(provider=provider, inputs=provider.select_inputs( Settings.key.address, 0.02), deck=deck, change_address=Settings.change, locktime=locktime) if verify: return cointoolkit_verify( spawn.hexlify()) # link to cointoolkit - verify if sign: tx = signtx(spawn) if send: return sendtx(tx) return tx.hexlify() return spawn.hexlify()
def transfer(self, deckid: str, receiver: list = None, amount: list = None, asset_specific_data: str = None, locktime: int = 0, verify: bool = False, sign: bool = False, send: bool = False) -> str: '''prepare CardTransfer transaction''' card = self.__new(deckid, receiver, amount, asset_specific_data) issue = pa.card_transfer(provider=provider, inputs=provider.select_inputs( Settings.key.address, 0.02), card=card, change_address=Settings.change, locktime=locktime) if verify: return cointoolkit_verify( issue.hexlify()) # link to cointoolkit - verify if sign: tx = signtx(issue) if send: return sendtx(tx) return tx.hexlify() return issue.hexlify()
def opreturn(self, string: hex, locktime: int = 0) -> str: '''send op_return transaction''' network_params = net_query(Settings.network) inputs = provider.select_inputs(Settings.key.address, 0.01) outs = [ tx_output(network=provider.network, value=Decimal(0), n=1, script=nulldata_script(bytes.fromhex(string))) ] # first round of txn making is done by presuming minimal fee change_sum = Decimal(inputs['total'] - network_params.min_tx_fee) outs.append( tx_output(network=provider.network, value=change_sum, n=len(outs) + 1, script=p2pkh_script(address=Settings.key.address, network=provider.network))) unsigned_tx = make_raw_transaction(network=provider.network, inputs=inputs['utxos'], outputs=outs, locktime=Locktime(locktime)) signedtx = sign_transaction(provider, unsigned_tx, Settings.key) return sendtx(signedtx)
def get_unspent(self, amount: int) -> str: '''quick find UTXO for this address''' try: return provider.select_inputs(Settings.key.address, 0.02)['utxos'][0].__dict__['txid'] except KeyError: print({'error': 'No UTXOs ;('})
def transfer_cards(deck, receivers, amounts, broadcast): validate_transfer(deck, amounts) utxo = provider.select_inputs(0.02) change_address = change(utxo) ct = pa.CardTransfer(deck=deck, receiver=receivers, amount=amounts) handle_transaction(pa.card_transfer(deck, ct, utxo, change_address), broadcast)
def cast(deck_id, vote_id, choice, broadcast): ''' cast a vote args = deck, vote_id, choice ''' vote = find_vote(deck_id, vote_id) choice = choice if isinstance(choice, int) else list(vote.choices).index(choice) inputs = provider.select_inputs(0.02) change_address = change(inputs) cast = pa.vote_cast(vote, choice, inputs, change_address) handle_transaction(cast, broadcast)
def new(deck_id, vote_json, broadcast): ''' Initialize new vote on the <deck> pacli vote new <deck> '{"choices": ["y", "n"], "count_mode": "SIMPLE", "description": "test", "start_block": int, "end_block": int}' ''' deck = find_deck(deck_id) vote_order = json.loads(vote_json) inputs = provider.select_inputs(0.02) change_address = change(inputs) vote = pa.Vote(version=1, deck=deck, **vote_order) handle_transaction(pa.vote_init(vote, inputs, change_address), broadcast)
def spawn(self, verify=False, **kwargs): '''prepare deck spawn transaction''' deck = self.__new(**kwargs) spawn = pa.deck_spawn(provider=provider, inputs=provider.select_inputs( Settings.key.address, 0.02), deck=deck, change_address=Settings.change) if verify: return cointoolkit_verify( spawn.hexlify()) # link to cointoolkit - verify return spawn.hexlify()
def default_account_utxo(amount): '''set default address to be used with pacli''' if "PACLI" not in provider.listaccounts().keys(): addr = provider.getaddressesbyaccount("PACLI") print("\n", "Please fund this address: {addr}".format(addr=addr)) return for i in provider.getaddressesbyaccount("PACLI"): try: return provider.select_inputs(amount, i) except ValueError: pass print( "\n", "Please fund one of the following addresses: {addrs}".format( addrs=provider.getaddressesbyaccount("PACLI"))) return
def sendto(self, address: Union[str], amount: Union[float], locktime: int = 0) -> str: '''send coins to address''' if not len(address) == amount: raise RecieverAmountMismatch network_params = net_query(Settings.network) inputs = provider.select_inputs(Settings.key.address, sum(amount)) outs = [] for addr, index, amount in zip(address, range(len(address)), amount): outs.append( tx_output(network=Settings.network, value=Decimal(amount), n=index, script=p2pkh_script(address=addr, network=Settings.network))) # first round of txn making is done by presuming minimal fee change_sum = Decimal(inputs['total'] - network_params.min_tx_fee) outs.append( tx_output(network=provider.network, value=change_sum, n=len(outs) + 1, script=p2pkh_script(address=Settings.key.address, network=provider.network))) unsigned_tx = make_raw_transaction(network=provider.network, inputs=inputs['utxos'], outputs=outs, locktime=Locktime(locktime)) signedtx = sign_transaction(provider, unsigned_tx, Settings.key) return sendtx(signedtx)
def transfer(self, deckid: str, receiver: list = None, amount: list = None, asset_specific_data: str = None, verify=False) -> str: '''prepare CardTransfer transaction''' card = self.__new(deckid, receiver, amount, asset_specific_data) issue = pa.card_transfer(provider=provider, inputs=provider.select_inputs( Settings.key.address, 0.02), card=card, change_address=Settings.change) if verify: return cointoolkit_verify( issue.hexlify()) # link to cointoolkit - verify return issue.hexlify()
def issue(issuence, broadcast): ''' Issue new cards of this deck. pacli card issue '{"deck": "deck_id", "receivers": [list of receiver addresses], "amounts": [list of amounts] } ''' deck = find_deck(issuence["deck"]) if not provider.gettransaction(deck.asset_id)["confirmations"] > 0: print( "\n", "You are trying to issue cards on a deck which has not been confirmed yet." ) if provider.validateaddress(deck.issuer)["ismine"]: try: utxo = provider.select_inputs(0.02, deck.issuer) except ValueError: throw("Please send funds to the deck issuing address: {0}".format( deck.issuer)) else: raise throw("You are not the owner of this deck.") receivers = issuence["receivers"] amounts = [ amount_to_exponent(float(i), deck.number_of_decimals) for i in issuence["amounts"] ] change_address = change(utxo) ct = pa.CardTransfer(deck=deck, receiver=receivers, amount=amounts) handle_transaction(pa.card_issue(deck, ct, utxo, change_address), broadcast)