def main(token_address, root_chain_address):
    client = Client(root_chain_address)
    
    maker_address = '0x0af467F2f6c20e3543B8a2a453e70DF034714aEB'
    make_order_hex = client.get_makeorder_txn(maker_address, token_address, Web3.toWei(10, 'ether'), Web3.toWei(1, 'ether'))
    if make_order_hex == None:
        print("No valid utxos to create make order txn")
        sys.exit(0)
        
    make_order_hash = utils.hashPersonalMessage(make_order_hex)
    signature = utils.sign(make_order_hash, bytes(bytearray.fromhex('46155f862a2249f0ee6d69122ead4ec56cf12a71049a3105a90b9708d7103f77')))
    client.submit_signed_makeorder_txn(maker_address, token_address, Web3.toWei(10, 'ether'), Web3.toWei(1, 'ether'), make_order_hex, signature.hex())
Beispiel #2
0
 def __init__(self):
     self.client = Client()
     self.db = plyvel.DB('/tmp/plasma_mvp_db/', create_if_missing=True)
     self.current_block = self.client.get_current_block_num()
     self.synced_block = 1
     self.client_cmds = dict(
         sync=self.sync_child_chain,
         deposit=self.deposit,
         send_tx=self.send_tx,
         submit_block=self.submit_block,
         withdraw=self.withdraw,
         help=self.help,
     )
Beispiel #3
0
def cli(ctx):
    ctx.obj = Client(os.environ['ROOT_CHAIN_ADDRESS'])
Beispiel #4
0
def cli(ctx):
    ctx.obj = Client()
Beispiel #5
0
class ClientParser():
    def __init__(self):
        self.client = Client()
        self.db = plyvel.DB('/tmp/plasma_mvp_db/', create_if_missing=True)
        self.current_block = self.client.get_current_block_num()
        self.synced_block = 1
        self.client_cmds = dict(
            sync=self.sync_child_chain,
            deposit=self.deposit,
            send_tx=self.send_tx,
            submit_block=self.submit_block,
            withdraw=self.withdraw,
            help=self.help,
        )

    def process_input(self, inp):
        self.inp = inp
        command = self.inp[0]
        if command not in self.client_cmds:
            print("Please enter a valid command ('or enter help')")
        else:
            return self.client_cmds[command]()

    def sync_child_chain(self):
        self.current_block = self.client.get_current_block_num()
        while self.synced_block < self.current_block:
            block_number = self.synced_block
            block = self.client.get_block(self.synced_block)
            self.db.put(bytes(block_number), utils.str_to_bytes(block))
            print("Synced %s" % self.synced_block)
            self.synced_block += 1
        print("Syncing complete!")

    def deposit(self):
        if len(self.inp) != 3:
            raise Exception("Wrong number of inputs for deposit")
        amount1 = int(self.inp[1])
        key = utils.normalize_key(self.inp[2])
        newOwner1 = utils.privtoaddr(key)
        newOwner2, amount2 = utils.normalize_address(b'\x00' * 20), 0
        tx = Transaction(0, 0, 0, 0, 0, 0, newOwner1, amount1, newOwner2,
                         amount2, 0)
        self.client.deposit(tx, key)
        print("Succesfully deposited %s to %s" % (amount1, newOwner1))

    def send_tx(self):
        if len(self.inp) != 14 and len(self.inp) != 13:
            raise Exception(
                "Wrong number of inputs for sending a transaction!")
        blknum1, tx_pos1, utxo_pos1 = int(self.inp[1]), int(self.inp[2]), int(
            self.inp[3])
        blknum2, tx_pos2, utxo_pos2 = int(self.inp[4]), int(self.inp[5]), int(
            self.inp[6])
        newowner1 = utils.normalize_address(self.inp[7])
        amount1 = int(self.inp[8])
        newowner2 = utils.normalize_address(self.inp[9])
        amount2 = int(self.inp[10])
        fee = int(self.inp[11])
        key1 = utils.normalize_key(self.inp[12])
        key2 = utils.normalize_key(self.inp[13]) if len(
            self.inp) == 14 else b''
        tx = Transaction(blknum1, tx_pos1, utxo_pos1, blknum2, tx_pos2,
                         utxo_pos2, newowner1, amount1, newowner2, amount2,
                         fee)
        tx.sign1(key1)
        if key2:
            tx.sign2(key2)
        self.client.apply_transaction(tx)
        print("Succesfully added transaction!")

    def submit_block(self):
        if len(self.inp) != 2:
            raise ("Wrong number of inputs to submit block")
        key = utils.normalize_key(self.inp[1])
        block = self.client.get_current_block()
        block = rlp.decode(utils.decode_hex(block), Block)
        block.make_mutable()
        block.sign(key)
        self.client.submit_block(block)
        print("Successfully submitted a block!")

    def withdraw(self):
        blknum, txindex, oindex = int(self.inp[1]), int(self.inp[2]), int(
            self.inp[3])
        txPos = [blknum, txindex, oindex]
        key1 = utils.normalize_key(self.inp[4])
        key2 = utils.normalize_key(self.inp[5]) if len(self.inp) == 6 else b''
        block = self.client.get_block(blknum)
        block = rlp.decode(utils.decode_hex(block), Block)
        tx = block.transaction_set[txindex]
        block.merkilize_transaction_set
        proof = block.merkle.create_membership_proof(tx.merkle_hash)
        confirmSig1 = confirm_tx(tx, block.merkle.root, key1)
        confirmSig2 = b''
        if key2:
            confirmSig2 = confirm_tx(tx, block.merkle.root, key2)
        sigs = tx.sig1 + tx.sig2 + confirmSig1 + confirmSig2
        self.client.withdraw(txPos, tx, proof, sigs)
        print("Successfully submitted a withdrawal")

    def help(self):
        print("Please enter one of the following commands:")
        for cmd in self.client_cmds:
            print(cmd)
Beispiel #6
0
from plasma.client.client import Client
from plasma_tools.config import tools_config


def process_cmd(command, raise_exception=True):
    command = "python plasma_tools/cli.py %s" % command
    print("cmd: " + command)
    status, output = subprocess.getstatusoutput(command)
    if status != 0 and raise_exception:
        raise Exception("None zero return code")
    print(output)
    return status, output


client = Client()


def main():
#     process_cmd("submitblock 3bb369fecdc16b93b99514d8ed9c2e87c5824cf4a6a98d2e8e91b7dd0c063304")
    utxos = client.get_utxo(sys.argv[2], "latest")
    for blknum, txindex, oindex, contractaddress, amount, tokenid in utxos:
        if contractaddress.lower() == tools_config["ERC20_CONTRACT_ADDRESS"][2:].lower():
            if amount >= 1:
                process_cmd("sendtx {0} {1} {2} 0 0 0 {4} {5} 1 0 {6} {8} {3} 0 {7} {7}".format(
                    blknum, txindex, oindex,
                    amount - 1, sys.argv[1],
                    tools_config["ERC20_CONTRACT_ADDRESS"],
                    sys.argv[2] if amount - 1 > 0 else "0x0", sys.argv[3],
                    tools_config["ERC20_CONTRACT_ADDRESS"] if amount - 1 > 0 else "0x0"
                ))