Ejemplo n.º 1
0
def new(deck, broadcast):
    ''' Spawn a new PeerAssets deck. Returns the deck span txid. 
        [deck] is deck description json. I.E. '{"name": "test", "number_of_decimals": 1, "issue_mode": "ONCE"}'
    '''

    deck = json.loads(deck)
    deck["network"] = Settings.network
    deck["production"] = Settings.production
    deck["version"] = Settings.deck_version
    #utxo = provider.select_inputs(0.02)  # we need 0.02 PPC
    utxo = default_account_utxo(0.02)
    if utxo:
        change_address = change(utxo)
    else:
        return
    raw_deck = pa.deck_spawn(pa.Deck(**deck),
                             inputs=utxo,
                             change_address=change_address)
    raw_deck_spawn = hexlify(raw_deck).decode()
    signed = provider.signrawtransaction(raw_deck_spawn)

    if broadcast:
        txid = provider.sendrawtransaction(signed["hex"])
        print("\n", txid, "\n")

        deck["asset_id"] = txid
        d = pa.Deck(**deck)
        pa.load_deck_p2th_into_local_node(provider, d)  # subscribe to deck
    else:
        print("\nraw transaction:\n", signed["hex"], "\n")
Ejemplo n.º 2
0
def new_deck(provider, deck):
    '''
    Spawn a new PeerAssets deck.

    pacli deck -new '{"name": "test", "number_of_decimals": 1, "issue_mode": "ONCE"}'

    Will return deck span txid.
    '''

    deck = json.loads(deck)
    deck["network"] = Settings.network
    utxo = provider.select_inputs(0.02)  ## we need 0.02 PPC
    change_address = change(utxo)
    raw_deck = pa.deck_spawn(pa.Deck(**deck),
                             inputs=utxo,
                             change_address=change_address,
                             prod=Settings.prod)
    raw_deck_spawn = hexlify(raw_deck).decode()
    signed = provider.signrawtransaction(raw_deck_spawn)
    txid = provider.sendrawtransaction(signed["hex"])
    print("\n", txid, "\n")

    deck["asset_id"] = txid
    d = pa.Deck(**deck)
    pa.load_deck_p2th_into_local_node(provider, d)  # subscribe to deck
Ejemplo n.º 3
0
def test_deck_spawn():

    provider = Explorer(network='tppc')
    inputs = provider.select_inputs("mthKQHpr7zUbMvLcj8GHs33mVcf91DtN6L", 0.02)
    change_address = "mthKQHpr7zUbMvLcj8GHs33mVcf91DtN6L"
    deck = pa.Deck(name="just-testing.", number_of_decimals=1, issue_mode=1,
                   network='tppc', production=True, version=1,
                   asset_specific_data='https://talk.peercoin.net/')

    deck_spawn = pa.deck_spawn(provider, deck, inputs, change_address)

    assert isinstance(deck_spawn, MutableTransaction)
Ejemplo n.º 4
0
    def __new(self,
              name: str,
              number_of_decimals: int,
              issue_mode: int,
              asset_specific_data: str = None):
        '''create a new deck.'''

        network = Settings.network
        production = Settings.production
        version = Settings.deck_version

        new_deck = pa.Deck(name, number_of_decimals, issue_mode, network,
                           production, version, asset_specific_data)

        return new_deck
def deck_spawn():
    '''spawn a new, random deck'''

    key = pa.Kutil(wif=wif, network='peercoin-testnet')

    name = ''.join([
        random.choice(string.ascii_letters + string.digits) for n in range(8)
    ])

    deck = pa.Deck(name=name,
                   number_of_decimals=3,
                   issue_mode=4,
                   version=1,
                   fee=0)

    unspent = provider.select_inputs(key.address, 0.02)

    new_deck = pa.deck_spawn(provider, key, deck, unspent, change_addr)

    Session.deck = deck

    print(new_deck)
Ejemplo n.º 6
0
'''
Issue cards for new deck.
'''

import pypeerassets as pa
from binascii import hexlify
import random

provider = pa.RpcNode(testnet=True)
change_addr = "mhPuRGwWRyhXRhzSfzgfoPPFHPXgAyZVSz"

deck = pa.Deck(**deck)  # use deck from deck_spawn.py example

## utxo must be owned by the deck issuer
utxo = provider.select_inputs(0.02, deck.issuer)

# generate 9 receiver addresses
receivers = [pa.Kutil(network="tppc").address for i in range(9)]
# amounts for the receivers
amounts = [random.randint(1, 999) for i in range(9)]

issue = pa.CardTransfer(deck, receivers, amounts)  # CardTransfer instance

raw_issue = hexlify(pa.card_issue(deck, issue, utxo, change_addr)).decode()

signed = provider.signrawtransaction(raw_issue)

provider.sendrawtransaction(signed["hex"])  # send the tx
Ejemplo n.º 7
0
'''
Spawn new PeerAssets deck on Peercoin testnet using local testnet node.
'''

import pypeerassets as pa
from binascii import hexlify

provider = pa.RpcNode(testnet=True)

utxo = provider.select_inputs(0.02)  ## we need 0.02 PPC
change_addr = "mwkFUPUrh6LsXyMvBY2mz6btiJjuTxGgT8"

new_deck = pa.Deck("my_new_testnet_deck",
                   number_of_decimals=2,
                   issue_mode="MULTI",
                   asset_specific_data="hello world.",
                   network="tppc")

raw_tx = hexlify(pa.deck_spawn(new_deck, utxo, change_addr)).decode()

signed = provider.signrawtransaction(raw_tx)

provider.sendrawtransaction(signed["hex"])  # send the tx
'''
Now wait for the tx confirm (1) and visit http://137.74.40.81:4000/ to see your assets listed.
'''
Ejemplo n.º 8
0
    # Deck Spawn

    print("Build, sign and send the Friendly Co. Deck spawning transaction...")

    rpc_node = RpcNode(testnet=True, username=RPC_USERNAME, password=RPC_PASSWORD)

    friendly_co_key = pa.Kutil(
        network="tppc",
        from_wif=rpc_node.dumpprivkey(FRIENDLY_CO),
    )

    deck = pa.Deck(
        name="Friendly Co. Deck",
        number_of_decimals=0,
        issue_mode=IssueMode.ONCE.value,
        network="tppc",
        production=False,
        version=1,
        issuer=FRIENDLY_CO,
    )

    deck_spawn_tx = pa.deck_spawn(
        provider=rpc_node,
        deck=deck,
        inputs=rpc_node.select_inputs(FRIENDLY_CO, 0.02),
        change_address=FRIENDLY_CO,
    )
    deck_spawn_tx = sign_transaction(rpc_node, deck_spawn_tx, friendly_co_key)
    rpc_node.sendrawtransaction(deck_spawn_tx.hexlify())

    print("Transaction to create the Friendly Co. Deck sent to the network!")