Exemplo n.º 1
0
 def __init__(self, raw):
     self.address = Address(raw['address'])
     self.balance = Amount(raw['balance'])
     self.unconfirmed_balance = Amount(raw['unconfirmedBalance'])
     self.public_key = None if raw['publicKey'] is None \
         else PublicKey.fromhex(raw['publicKey'])
     if raw['secondPublicKey']:
         self.second_public_key = PublicKey.fromhex(raw['secondPublicKey'])
     else:
         self.second_public_key = None
     self.second_signature = bool(raw['secondSignature'])
     self.unconfirmed_second_signature = bool(raw['unconfirmedSignature'])
Exemplo n.º 2
0
 def __init__(self, raw):
     self.address = Address(raw['address'])
     self.public_key = PublicKey.fromhex(raw['publicKey'])
     self.username = str(raw['username'])
     self.approval = float(raw['approval'])
     self.productivity = float(raw['productivity'])
     if 'cmb' in raw:
         self.consecutive_missed_blocks = int(raw['cmb'])
     else:
         self.consecutive_missed_blocks = None
     self.missed_blocks = int(raw['missedblocks'])
     self.produced_blocks = int(raw['producedblocks'])
     self.rank = int(raw['rank'])
     if 'rate' in raw:
         self.rate = int(raw['rate'])
     else:
         self.rate = None
     self.vote = Amount(raw['vote'])
     if 'votesWeight' in raw:
         self.votes_weight = int(raw['votesWeight'])
     else:
         self.votes_weight = None
     if 'voters_cnt' in raw:
         self.voters_count = int(raw['voters_cnt'])
     else:
         self.voters_count = None
     if 'register_timestamp' in raw:
         self.registration_time = Timestamp(raw['register_timestamp'])
     else:
         self.register_timestamp = None
Exemplo n.º 3
0
 def __init__(self, raw):
     self.current_block = BlockInfo(raw['currentBlock'])
     self.current_block_slot = int(raw['currentBlockSlot'])
     if 'relays' in raw['currentBlock']:
         self.current_block_relays = int(raw['currentBlock']['relays'])
     else:
         self.current_block_relays = None
     self.delegates = [PublicKey.fromhex(d) for d in raw['delegates']]
Exemplo n.º 4
0
 def test_derive_public_key(self):
     for (idx,
          raw) in enumerate(self.fixtures.genesis_delegates['delegates']):
         with self.subTest(username=raw['username'], index=idx):
             sk = SecretKey.from_passphrase(raw['secret'])
             self.assertIsInstance(sk, SecretKey)
             pk = sk.derive_public_key()
             self.assertIsInstance(pk, PublicKey)
             self.assertEqual(pk, PublicKey.fromhex(raw['publicKey']))
Exemplo n.º 5
0
    def test_verify(self):
        msg = b'Hello, world!'
        sig = Signature.fromhex(
            '90906e741ccf000046672a4f7350dde1e7f6efe32389e8af79930ea6d42cbddc'
            '1f68419809da74bf69a09d9bac9cd3c1a32cf081a655e5fa44590be70c264c0a')
        pk = PublicKey.fromhex(
            '9d3058175acab969f41ad9b86f7a2926c74258670fe56b37c429c01fca9f2f0f')

        self.assertEqual(pk.verify(sig, msg), True)
        self.assertEqual(pk.verify(sig, b'Wrong message'), False)
Exemplo n.º 6
0
 def test_add_transactions(self):
     # Resubmit an old tx
     tx = SendTx(
         sender_public_key=PublicKey.fromhex(
             'b3dc9171d784a3669482103951e0e8e89429f78ee5634950f0f4a7f8fad19378'
         ),
         recipient=Address('7851658041862611161R'),
         amount=Amount(3500000000),
         fee=Amount(10000000),
         timestamp=Timestamp(71278993),
         signature=Signature.fromhex(
             'f3fa873fba4619a82becef2c3921d883b44055f6644acc6721be47e451f45ca0'
             '0eb657f476f08b7b5f3035cbe60b7b2e5d68290e8391bdc152340df75c5f390f'
         ),
     )
     self.client.transactions.add_transactions(tx)
Exemplo n.º 7
0
 def get_forged_by_account(
     self,
     generator_public_key: PublicKey,
     start_time: Optional[Timestamp] = None,
     end_time: Optional[Timestamp] = None,
 ) -> DelegateForgingResult:
     r = self._get('/delegates/forging/getForgedByAccount',
                   params={
                       'generatorPublicKey':
                       None if generator_public_key is None else
                       generator_public_key.hex(),
                       'start':
                       None if start_time is None else int(start_time),
                       'end':
                       None if end_time is None else int(end_time),
                   })
     return DelegateForgingResult(r)
Exemplo n.º 8
0
 def __init__(self, raw):
     self.block_id = str(raw['id'])
     self.version = int(raw['version'])
     self.timestamp = Timestamp(raw['timestamp'])
     self.height = int(raw['height'])
     if raw['previousBlock']:
         self.previous_block_id = str(raw['previousBlock'])
     else:
         self.previous_block_id = None
     self.number_of_transactions = int(raw['numberOfTransactions'])
     self.total_amount = Amount(raw['totalAmount'])
     self.total_fee = Amount(raw['totalFee'])
     self.reward = Amount(raw['reward'])
     self.payload_length = int(raw['payloadLength'])
     self.payload_hash = bytes.fromhex(raw['payloadHash'])
     self.generator_public_key = PublicKey.fromhex(raw['generatorPublicKey'])
     self.block_signature = Signature.fromhex(raw['blockSignature'])
     self.transactions = [TransactionInfo(t) for t in raw['transactions']]
Exemplo n.º 9
0
 def test_valid(self):
     value = PublicKey([
         0,
         1,
         2,
         3,
         4,
         5,
         6,
         7,
         8,
         9,
         10,
         11,
         12,
         13,
         14,
         15,
         16,
         17,
         18,
         19,
         20,
         21,
         22,
         23,
         24,
         25,
         26,
         27,
         28,
         29,
         30,
         31,
     ])
     self.assertIsInstance(value, PublicKey)
Exemplo n.º 10
0
 def test_get_voters(self):
     self.client.delegates.get_voters(public_key=PublicKey.fromhex(
         '8a11b8b63427ab4d3bd5114bb7264d635cbcb7359fcc7e938c3603d32e154a3f'
     ), )
Exemplo n.º 11
0
 def test_get_forged_by_account(self):
     self.client.delegates.get_forged_by_account(
         generator_public_key=PublicKey.fromhex(
             '8a11b8b63427ab4d3bd5114bb7264d635cbcb7359fcc7e938c3603d32e154a3f'
         ), )
Exemplo n.º 12
0
 def test_invalid(self):
     with self.assertRaises(ValueError):
         PublicKey([0, 1, 2])
Exemplo n.º 13
0
 def test_derive_address(self):
     pk = PublicKey.fromhex(
         'b3dc9171d784a3669482103951e0e8e89429f78ee5634950f0f4a7f8fad19378')
     self.assertEqual(Address('10820014087913201714R'), pk.derive_address())
Exemplo n.º 14
0
 def __init__(self, raw):
     self.address = Address(raw['address'])
     self.public_key = PublicKey.fromhex(raw['publicKey'])
     self.username = raw['username']
     self.balance = Amount(raw['balance'])
Exemplo n.º 15
0
 def get_voters(self, public_key: PublicKey) -> List[VoterInfo]:
     r = self._get('/delegates/voters',
                   params={
                       'publicKey': public_key.hex(),
                   })
     return [VoterInfo(a) for a in r['accounts']]
Exemplo n.º 16
0
 def __init__(self, raw):
     self.enabled = bool(raw['enabled'])
     self.delegates = [PublicKey.fromhex(d) for d in raw['delegates']]