Пример #1
0
 def test_create_negative_fee(self):
     with self.assertRaises(ValueError):
         TokenTransaction.create(
             symbol=b'QRL',
             name=b'Quantum Resistant Ledger',
             owner=
             b'\x01\x03\x17F=\xcdX\x1bg\x9bGT\xf4ld%\x12T\x89\xa2\x82h\x94\xe3\xc4*Y\x0e\xfbh\x06E\x0c\xe6\xbfRql',
             decimals=4,
             initial_balances=[],
             fee=-1,
             xmss_pk=self.alice.pk)
Пример #2
0
 def test_create_negative_fee(self):
     with self.assertRaises(ValueError):
         TokenTransaction.create(
             addr_from=self.alice.get_address().encode(),
             symbol=b'QRL',
             name=b'Quantum Resistant Ledger',
             owner=
             b'Q223bc5e5b78edfd778b1bf72702061cc053010711ffeefb9d969318be5d7b86b021b73c2',
             decimals=4,
             initial_balances=[],
             fee=-1,
             xmss_pk=self.alice.pk(),
             xmss_ots_index=self.alice.get_index())
Пример #3
0
    def test_validate_tx(self):
        initial_balances = list()
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.alice.get_address().encode(),
                                  amount=400000000))
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.bob.get_address().encode(),
                                  amount=200000000))
        tx = TokenTransaction.create(
            addr_from=self.alice.get_address().encode(),
            symbol=b'QRL',
            name=b'Quantum Resistant Ledger',
            owner=
            b'Q223bc5e5b78edfd778b1bf72702061cc053010711ffeefb9d969318be5d7b86b021b73c2',
            decimals=4,
            initial_balances=initial_balances,
            fee=1,
            xmss_pk=self.alice.pk(),
            xmss_ots_index=self.alice.get_index())

        # We must sign the tx before validation will work.
        tx.sign(self.alice)

        # We have not touched the tx: validation should pass.
        self.assertTrue(tx.validate_or_raise())
Пример #4
0
def tx_token(ctx, src, symbol, name, owner, decimals, fee, ots_key_index):
    """
    Create Token Transaction, that results into the formation of new token if accepted.
    """

    if not ctx.obj.remote:
        click.echo('This command is unsupported for local wallets')
        return

    initial_balances = []

    while True:
        address = click.prompt('Address ', default='')
        if address == '':
            break
        amount = int(click.prompt('Amount ')) * (10**int(decimals))
        initial_balances.append(
            qrl_pb2.AddressAmount(address=address.encode(), amount=amount))

    try:
        address_src, src_xmss = _select_wallet(ctx, src)
        if not src_xmss:
            click.echo("A local wallet is required to sign the transaction")
            quit(1)

        address_src_pk = src_xmss.pk()
        src_xmss.set_index(int(ots_key_index))
        address_src_otsidx = src_xmss.get_index()
        address_owner = owner.encode()
        # FIXME: This could be problematic. Check
        fee_shor = int(fee * 1.e8)
    except KeyboardInterrupt as e:
        click.echo("Error validating arguments")
        quit(1)

    try:
        channel = grpc.insecure_channel(ctx.obj.node_public_address)
        stub = qrl_pb2_grpc.PublicAPIStub(channel)

        tx = TokenTransaction.create(addr_from=address_src,
                                     symbol=symbol.encode(),
                                     name=name.encode(),
                                     owner=address_owner,
                                     decimals=decimals,
                                     initial_balances=initial_balances,
                                     fee=fee_shor,
                                     xmss_pk=address_src_pk,
                                     xmss_ots_index=address_src_otsidx)

        tx.sign(src_xmss)

        pushTransactionReq = qrl_pb2.PushTransactionReq(
            transaction_signed=tx.pbdata)
        pushTransactionResp = stub.PushTransaction(pushTransactionReq,
                                                   timeout=5)

        print(pushTransactionResp.some_response)
    except Exception as e:
        print("Error {}".format(str(e)))
Пример #5
0
Файл: cli.py Проект: fanff/QRL
def tx_token(ctx, src, symbol, name, owner, decimals, fee, ots_key_index):
    """
    Create Token Transaction, that results into the formation of new token if accepted.
    """

    if not ctx.obj.remote:
        click.echo('This command is unsupported for local wallets')
        return

    initial_balances = []

    while True:
        address = click.prompt('Address ', default='')
        if address == '':
            break
        amount = int(click.prompt('Amount ')) * (10**int(decimals))
        initial_balances.append(qrl_pb2.AddressAmount(address=address.encode(), amount=amount))

    try:
        address_src, src_xmss = _select_wallet(ctx, src)
        if not src_xmss:
            click.echo("A local wallet is required to sign the transaction")
            quit(1)

        address_src_pk = src_xmss.pk()
        src_xmss.set_index(int(ots_key_index))
        address_src_otsidx = src_xmss.get_index()
        address_owner = owner.encode()
        # FIXME: This could be problematic. Check
        fee_shor = int(fee * 1.e9)
    except KeyboardInterrupt as e:
        click.echo("Error validating arguments")
        quit(1)

    try:
        channel = grpc.insecure_channel(ctx.obj.node_public_address)
        stub = qrl_pb2_grpc.PublicAPIStub(channel)

        tx = TokenTransaction.create(addr_from=address_src,
                                     symbol=symbol.encode(),
                                     name=name.encode(),
                                     owner=address_owner,
                                     decimals=decimals,
                                     initial_balances=initial_balances,
                                     fee=fee_shor,
                                     xmss_pk=address_src_pk,
                                     xmss_ots_index=address_src_otsidx)

        tx.sign(src_xmss)

        pushTransactionReq = qrl_pb2.PushTransactionReq(transaction_signed=tx.pbdata)
        pushTransactionResp = stub.PushTransaction(pushTransactionReq, timeout=5)

        print(pushTransactionResp.some_response)
    except Exception as e:
        print("Error {}".format(str(e)))
Пример #6
0
def get_token_transaction(xmss1, xmss2, amount1=400000000, amount2=200000000, fee=1) -> TokenTransaction:
    initial_balances = list()
    initial_balances.append(qrl_pb2.AddressAmount(address=xmss1.address,
                                                  amount=amount1))
    initial_balances.append(qrl_pb2.AddressAmount(address=xmss2.address,
                                                  amount=amount2))

    return TokenTransaction.create(symbol=b'QRL',
                                   name=b'Quantum Resistant Ledger',
                                   owner=xmss1.address,
                                   decimals=4,
                                   initial_balances=initial_balances,
                                   fee=fee,
                                   xmss_pk=xmss1.pk)
Пример #7
0
 def create_token_txn(symbol: bytes,
                      name: bytes,
                      owner: bytes,
                      decimals: int,
                      initial_balances,
                      fee: int,
                      xmss_pk: bytes,
                      master_addr: bytes):
     return TokenTransaction.create(symbol,
                                    name,
                                    owner,
                                    decimals,
                                    initial_balances,
                                    fee,
                                    xmss_pk,
                                    master_addr)
Пример #8
0
    def create_unsigned_tx(self, transaction):
        if transaction.type == qrl_pb2.Transaction.TRANSFER:
            return TransferTransaction.create(transaction.addr_from,
                                              transaction.Transfer.addr_to,
                                              transaction.Transfer.amount,
                                              transaction.Transfer.fee,
                                              transaction.xmss_pk,
                                              transaction.xmss_ots_index)

        elif transaction.type == qrl_pb2.Transaction.LATTICE:
            return LatticePublicKey.create(transaction.addr_from,
                                           transaction.LatticePublicKey.kyber_pk,
                                           transaction.LatticePublicKey.tesla_pk,
                                           transaction.xmss_pk,
                                           transaction.xmss_ots_index)

        elif transaction.type == qrl_pb2.Transaction.MESSAGE:
            return MessageTransaction.create(transaction.addr_from,
                                             transaction.Message.message_hash,
                                             transaction.Message.fee,
                                             transaction.xmss_pk,
                                             transaction.xmss_ots_index)

        elif transaction.type == qrl_pb2.Transaction.TOKEN:
            return TokenTransaction.create(transaction.addr_from,
                                           transaction.Token.symbol,
                                           transaction.Token.name,
                                           transaction.Token.owner,
                                           transaction.Token.decimals,
                                           transaction.Token.initial_balances,
                                           transaction.Token.fee,
                                           transaction.xmss_pk,
                                           transaction.xmss_ots_index)

        elif transaction.type == qrl_pb2.Transaction.TRANSFERTOKEN:
            return TransferTokenTransaction.create(transaction.addr_from,
                                                   transaction.TransferToken.token_txhash,
                                                   transaction.TransferToken.addr_to,
                                                   transaction.TransferToken.amount,
                                                   transaction.TransferToken.fee,
                                                   transaction.xmss_pk,
                                                   transaction.xmss_ots_index)

        else:
            return None
Пример #9
0
 def test_create(self):
     # Alice creates Token
     initial_balances = list()
     initial_balances.append(
         qrl_pb2.AddressAmount(address=self.alice.address,
                               amount=400000000))
     initial_balances.append(
         qrl_pb2.AddressAmount(address=self.bob.address, amount=200000000))
     tx = TokenTransaction.create(
         symbol=b'QRL',
         name=b'Quantum Resistant Ledger',
         owner=
         b'\x01\x03\x17F=\xcdX\x1bg\x9bGT\xf4ld%\x12T\x89\xa2\x82h\x94\xe3\xc4*Y\x0e\xfbh\x06E\x0c\xe6\xbfRql',
         decimals=4,
         initial_balances=initial_balances,
         fee=1,
         xmss_pk=self.alice.pk)
     self.assertTrue(tx)
Пример #10
0
 def create_token_txn(addr_from: bytes,
                      symbol: bytes,
                      name: bytes,
                      owner: bytes,
                      decimals: int,
                      initial_balances,
                      fee: int,
                      xmss_pk: bytes,
                      xmss_ots_index: int):
     return TokenTransaction.create(addr_from,
                                    symbol,
                                    name,
                                    owner,
                                    decimals,
                                    initial_balances,
                                    fee,
                                    xmss_pk,
                                    xmss_ots_index)
Пример #11
0
 def create_token_txn(addr_from: bytes,
                      symbol: bytes,
                      name: bytes,
                      owner: bytes,
                      decimals: int,
                      initial_balances,
                      fee: int,
                      xmss_pk: bytes,
                      xmss_ots_index: int):
     return TokenTransaction.create(addr_from,
                                    symbol,
                                    name,
                                    owner,
                                    decimals,
                                    initial_balances,
                                    fee,
                                    xmss_pk,
                                    xmss_ots_index)
Пример #12
0
    def test_to_json(self):
        initial_balances = list()
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.alice.address,
                                  amount=400000000))
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.bob.address, amount=200000000))
        tx = TokenTransaction.create(
            addr_from=self.alice.address,
            symbol=b'QRL',
            name=b'Quantum Resistant Ledger',
            owner=
            b'\x01\x03\x17F=\xcdX\x1bg\x9bGT\xf4ld%\x12T\x89\xa2\x82h\x94\xe3\xc4*Y\x0e\xfbh\x06E\x0c\xe6\xbfRql',
            decimals=4,
            initial_balances=initial_balances,
            fee=1,
            xmss_pk=self.alice.pk)
        txjson = tx.to_json()

        self.assertEqual(json.loads(test_json_Token), json.loads(txjson))
Пример #13
0
    def test_validate_tx3(self):
        initial_balances = list()
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.alice.address, amount=1000))
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.bob.address, amount=1000))
        tx = TokenTransaction.create(
            symbol=b'QRL',
            name=b'Quantum Resistant Ledger',
            owner=
            b'\x01\x03\x17F=\xcdX\x1bg\x9bGT\xf4ld%\x12T\x89\xa2\x82h\x94\xe3\xc4*Y\x0e\xfbh\x06E\x0c\xe6\xbfRql',
            decimals=15,
            initial_balances=initial_balances,
            fee=1,
            xmss_pk=self.alice.pk)

        # We must sign the tx before validation will work.
        tx.sign(self.alice)

        # We have not touched the tx: validation should pass.
        self.assertTrue(tx.validate_or_raise())
Пример #14
0
 def test_create(self):
     # Alice creates Token
     initial_balances = list()
     initial_balances.append(
         qrl_pb2.AddressAmount(address=self.alice.get_address().encode(),
                               amount=400000000))
     initial_balances.append(
         qrl_pb2.AddressAmount(address=self.bob.get_address().encode(),
                               amount=200000000))
     tx = TokenTransaction.create(
         addr_from=self.alice.get_address().encode(),
         symbol=b'QRL',
         name=b'Quantum Resistant Ledger',
         owner=
         b'Q223bc5e5b78edfd778b1bf72702061cc053010711ffeefb9d969318be5d7b86b021b73c2',
         decimals=4,
         initial_balances=initial_balances,
         fee=1,
         xmss_pk=self.alice.pk(),
         xmss_ots_index=self.alice.get_index())
     self.assertTrue(tx)
Пример #15
0
    def test_validate_tx2(self):
        initial_balances = list()
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.alice.address,
                                  amount=10000000000000000000))
        initial_balances.append(
            qrl_pb2.AddressAmount(address=self.bob.address,
                                  amount=10000000000000000000))
        tx = TokenTransaction.create(
            symbol=b'QRL',
            name=b'Quantum Resistant Ledger',
            owner=
            b'\x01\x03\x17F=\xcdX\x1bg\x9bGT\xf4ld%\x12T\x89\xa2\x82h\x94\xe3\xc4*Y\x0e\xfbh\x06E\x0c\xe6\xbfRql',
            decimals=4,
            initial_balances=initial_balances,
            fee=1,
            xmss_pk=self.alice.pk)

        # We must sign the tx before validation will work.
        tx.sign(self.alice)

        # Transaction Validation should fail as the decimals is higher than the possible decimals
        with self.assertRaises(ValueError):
            self.assertFalse(tx.validate_or_raise())
Пример #16
0
def tx_token(ctx, src, master, symbol, name, owner, decimals, fee,
             ots_key_index):
    """
    Create Token Transaction, that results into the formation of new token if accepted.
    """

    if not ctx.obj.remote:
        click.echo('This command is unsupported for local wallets')
        return

    initial_balances = []

    while True:
        address = click.prompt('Address ', default='')
        if address == '':
            break
        amount = int(click.prompt('Amount ')) * (10**int(decimals))
        initial_balances.append(
            qrl_pb2.AddressAmount(address=_parse_qaddress(address),
                                  amount=amount))

    try:
        _, src_xmss = _select_wallet(ctx, src)
        if not src_xmss:
            click.echo("A local wallet is required to sign the transaction")
            quit(1)

        address_src_pk = src_xmss.pk
        src_xmss.set_ots_index(int(ots_key_index))
        address_owner = _parse_qaddress(owner)
        master_addr = _parse_qaddress(master)
        # FIXME: This could be problematic. Check
        fee_shor = _shorize(fee)

        if len(name) > config.dev.max_token_name_length:
            raise Exception("Token name must be shorter than {} chars".format(
                config.dev.max_token_name_length))
        if len(symbol) > config.dev.max_token_name_length:
            raise Exception(
                "Token symbol must be shorter than {} chars".format(
                    config.dev.max_token_name_length))

    except KeyboardInterrupt:
        click.echo("Terminated by user")
        quit(1)
    except Exception as e:
        click.echo("Error validating arguments: {}".format(e))
        quit(1)

    try:
        stub = ctx.obj.get_stub_public_api()
        tx = TokenTransaction.create(symbol=symbol.encode(),
                                     name=name.encode(),
                                     owner=address_owner,
                                     decimals=decimals,
                                     initial_balances=initial_balances,
                                     fee=fee_shor,
                                     xmss_pk=address_src_pk,
                                     master_addr=master_addr)

        tx.sign(src_xmss)

        pushTransactionReq = qrl_pb2.PushTransactionReq(
            transaction_signed=tx.pbdata)
        pushTransactionResp = stub.PushTransaction(pushTransactionReq,
                                                   timeout=5)

        print(pushTransactionResp.error_code)
    except Exception as e:
        print("Error {}".format(str(e)))