Exemplo n.º 1
0
 def test_sign(self):
     hash_val = b'0' * 32
     key = b'0' * 32
     sig = (
         b'\xf6\x12[\x1b\x04\xe6\xdb\xcb\xe5\xd2\x88\xe41\x89J\xb5\x83\x18\x11\xa8'
         b'A\xed\xfcRK\x9c5i{\xbd\xab|r\xdb\xeeX\x1dp\x9a\xb6\x0e\\<\xa2X\x81\x17\xc5'
         b'$\xfa\x86i\xe3\xf5\xc0\xd1\xd9d}+\x8f\xceqE\x1c')
     assert sign(hash_val, key) == sig
Exemplo n.º 2
0
    def test_run(self, child_chain):
        block = self._generate_dummy_block()
        when(child_chain).get_current_block().thenReturn(rlp.encode(block).hex())

        key = (b'\xa1\x89i\x81|,\xef\xad\xf5+\x93\xeb \xf9\x17\xdc\xe7`\xce'
               b'\x13\xb2\xac\x90%\xe06\x1a\xd1\xe7\xa1\xd4H')
        job = SubmitBlockJob(child_chain, key)
        job.run()

        sig = sign(block.hash, key)
        verify(child_chain).submit_block(sig.hex())
Exemplo n.º 3
0
    def apply_deposit(self, depositor, amount, uid):
        new_owner = utils.normalize_address(depositor)

        if not self.current_block.get_tx_by_uid(uid):
            deposit_tx = Transaction(0, uid, amount, new_owner)
            self.current_block.add_tx(deposit_tx)
            sig = sign(self.current_block.hash, self.key)
            self.submit_block(sig.hex(), True, uid)
            return deposit_tx.hash

        err_msg = 'deposit of uid: {} is already applied previously'.format(uid)
        raise DepositAlreadyAppliedException(err_msg)
Exemplo n.º 4
0
 def submit_block(self, key):
     key = utils.normalize_key(key)
     block = self.get_current_block()
     sig = sign(block.hash, key)
     self.child_chain.submit_block(sig.hex())
Exemplo n.º 5
0
 def submit_block(self):
     # TODO: this method should be a cron job in child chain
     block = self.get_current_block()
     sig = sign(block.hash, self.key)
     self.child_chain.submit_block(sig.hex())
Exemplo n.º 6
0
 def sign(self, key):
     self.sig = sign(self.hash, key)
Exemplo n.º 7
0
 def run(self):
     block = self._get_current_block()
     sig = sign(block.hash, self.key)
     self.child_chain.submit_block(sig.hex())