Esempio n. 1
0
 def send_transaction(self, slot, prev_block, new_owner):
     new_owner = utils.normalize_address(new_owner)
     tx = Transaction(slot, prev_block, 1, new_owner)
     tx.make_mutable()
     tx.sign(self.key)
     tx.make_immutable()
     self.child_chain.send_transaction(rlp.encode(tx, Transaction).hex())
     return tx
Esempio n. 2
0
    def start_exit(self, slot, prev_tx_blk_num, tx_blk_num):
        '''
        As a user, you declare that you want to exit a coin at slot `slot`
        at the state which happened at block `tx_blk_num` and you also need to
        reference a previous block
        '''
        # TODO The actual proof information should be passed to a user from its
        # previous owners, this is a hacky way of getting the info from the
        # operator which sould be changed in the future after the exiting
        # process is more standardized
        if tx_blk_num % self.child_block_interval != 0:
            # In case the sender is exiting a Deposit transaction, they should
            # just create a signed transaction to themselves. There is no need
            # for a merkle proof.

            # prev_block = 0 , denomination = 1
            exiting_tx = Transaction(
                slot, 0, 1, self.token_contract.account.address
            )
            exiting_tx.make_mutable()
            exiting_tx.sign(self.key)
            exiting_tx.make_immutable()
            tx_hash, gas_used = self.root_chain.start_exit(
                slot,
                b'0x0',
                rlp.encode(exiting_tx, UnsignedTransaction),
                b'0x0',
                b'0x0',
                exiting_tx.sig,
                0,
                tx_blk_num,
            )
        else:
            # Otherwise, they should get the raw tx info from the block
            # And the merkle proof and submit these
            exiting_tx, exiting_tx_proof = self.get_tx_and_proof(
                tx_blk_num, slot
            )
            prev_tx, prev_tx_proof = self.get_tx_and_proof(
                prev_tx_blk_num, slot
            )

            tx_hash, gas_used = self.root_chain.start_exit(
                slot,
                rlp.encode(prev_tx, UnsignedTransaction),
                rlp.encode(exiting_tx, UnsignedTransaction),
                prev_tx_proof,
                exiting_tx_proof,
                exiting_tx.sig,
                prev_tx_blk_num,
                tx_blk_num,
            )
        return tx_hash, gas_used
Esempio n. 3
0
    def challenge_before(self, slot, prev_tx_blk_num, tx_blk_num):
        if tx_blk_num % self.child_block_interval != 0:
            # In case the sender is exiting a Deposit transaction, they should
            # just create a signed transaction to themselves. There is no need
            # for a merkle proof.

            # prev_block = 0 , denomination = 1
            exiting_tx = Transaction(
                slot, 0, 1, self.token_contract.account.address
            )
            exiting_tx.make_mutable()
            exiting_tx.sign(self.key)
            exiting_tx.make_immutable()
            tx_hash, gas_used = self.root_chain.challenge_before(
                slot,
                b'0x0',
                rlp.encode(exiting_tx, UnsignedTransaction),
                b'0x0',
                b'0x0',
                exiting_tx.sig,
                0,
                tx_blk_num,
            )
        else:
            # Otherwise, they should get the raw tx info from the block
            # And the merkle proof and submit these
            exiting_tx, exiting_tx_proof = self.get_tx_and_proof(
                tx_blk_num, slot
            )
            prev_tx, prev_tx_proof = self.get_tx_and_proof(
                prev_tx_blk_num, slot
            )

            tx_hash, gas_used = self.root_chain.challenge_before(
                slot,
                rlp.encode(prev_tx, UnsignedTransaction),
                rlp.encode(exiting_tx, UnsignedTransaction),
                prev_tx_proof,
                exiting_tx_proof,
                exiting_tx.sig,
                prev_tx_blk_num,
                tx_blk_num,
            )
        return tx_hash, gas_used
Esempio n. 4
0
import rlp

from child_chain.transaction import Transaction, UnsignedTransaction
from dependency_config import container

token_contract = container.get_token('alice')
tx = Transaction(5, 0, 1, token_contract.account.address)
tx_hex = rlp.encode(tx, UnsignedTransaction).hex()
print('Transaction(5, 0, 1, {}): {}'.format(token_contract.account.address,
                                            tx_hex))

tx = Transaction(5, 85478557858583, 1, token_contract.account.address)
tx_hex = rlp.encode(tx, UnsignedTransaction).hex()
print('Transaction(5, 85478557858583, 1, {}): {}'.format(
    token_contract.account.address, tx_hex))

tx.sign(token_contract.account.privateKey)
print('Transaction Hash: {}'.format(tx.hash.hex()))
print('Transaction Sig: {}'.format(tx.sig.hex()))