예제 #1
0
def remote_transactions_received_handler(sender, transactions, peer, **kwargs):
    "receives rlp.decoded serialized"
    txl = [Transaction.deserialize(rlp.encode(tx)) for tx in transactions]
    log_api.debug('remote_transactions_received', count=len(txl), remote_id=peer)
    for tx in txl:
        peermanager.txfilter.add(tx, peer)  # FIXME
        chain_manager.add_transaction(tx)
예제 #2
0
파일: block.py 프로젝트: ksl20200108/8.3
 def deserialize(cls, data):
     block_header_dict = data['block_header']
     block_header = BlockHeader.deserialize(block_header_dict)
     transactions = data["transactions"]
     txs = []
     for transaction in transactions:
         txs.append(Transaction.deserialize(transaction))
     return cls(block_header, txs)
예제 #3
0
 def handle_transaction(self, msg):
     data = msg.get("data", {})
     tx = Transaction.deserialize(data)
     tx_pool = TxPool()
     tx_pool.add(tx)
     if tx_pool.is_full():
         bc.add_block(tx_pool.txs)
         log.info("mined a block")
         tx_pool.clear()
예제 #4
0
def remote_transactions_received_handler(sender, transactions, peer, **kwargs):
    "receives rlp.decoded serialized"
    txl = [Transaction.deserialize(rlp.encode(tx)) for tx in transactions]
    log_api.debug('remote_transactions_received',
                  count=len(txl),
                  remote_id=peer)
    for tx in txl:
        peermanager.txfilter.add(tx, peer)  # FIXME
        chain_manager.add_transaction(tx)
예제 #5
0
def applytx(client, transaction):
    """Absorb a transaction into the next block.

    This command sends a transaction to the server, which will presumably
    validate it, include it in its memory pool, and further announce it to the
    network. The server's response will be returned.

    TRANSACTION must a signed transaction in hex-encoding.
    """
    tx = Transaction.deserialize(str(transaction))
    pecho(client.applytx(tx))
예제 #6
0
def applytx(client, transaction):
    """Absorb a transaction into the next block.

    This command sends a transaction to the server, which will presumably
    validate it, include it in its memory pool, and further announce it to the
    network. The server's response will be returned.

    TRANSACTION must a signed transaction in hex-encoding.
    """
    tx = Transaction.deserialize(str(transaction))
    pecho(client.applytx(tx))
예제 #7
0
 def handle_transaction(self, msg):
     tx_pool = TxPool()
     txs = msg.get("data", {})
     for tx_data in txs:
         tx = Transaction.deserialize(tx_data)
         tx_pool.add(tx)
     if tx_pool.is_full():
         bc = BlockChain()
         bc.add_block(tx_pool.txs)
         log.info("add block")
         tx_pool.clear()
     msg = Msg(Msg.NONE_MSG, "")
     return msg
예제 #8
0
파일: network.py 프로젝트: ksl20200108/8.3
 def handle_transaction(self, msg, conn, addr):  # 7.20
     log.info("------server handle_transaction------")  # 7.8
     tx_pool = TxPool()
     txs = msg.get("data", {})
     for tx_data in txs:
         log.info("------server handle_transaction: for------")  # 7.8
         tx = Transaction.deserialize(tx_data)
         is_new = True
         if tx_pool.is_new(tx):  # 7.20
             # 7.20
             log.info(
                 "------server never get this transaction before------")
             bc = BlockChain()
             ls_bl = bc.get_last_block()
             if ls_bl:
                 ls_height = ls_bl.block_header.height
                 for i in range(0, ls_height + 1):
                     while True:
                         block = None
                         try:
                             block = bc.get_block_by_height(i)
                         except:
                             continue
                         if block:
                             break
                     bc_txs = block._transactions
                     if bc_txs:
                         for transaction in bc_txs:
                             if transaction.txid == tx.txid:
                                 log.info("------old transaction------")
                                 log.info("------the id is: " +
                                          str(tx.txid) + "------")  # 7.20
                                 is_new = False
                                 # break
                             else:
                                 log.info("------brand new------")
                                 log.info("------the id is: " +
                                          str(tx.txid) + "------")  # 7.20
                     if not is_new:
                         break
             if is_new:
                 tx_pool.add(tx)
                 log.info("------server add this transaction------")
                 log.info("------the id is: " + str(tx.txid) + "------")
                 server1 = PeerServer()
                 server1.broadcast_tx(tx)
                 log.info("------server handle_transaction broadcast------")
     msg = Msg(Msg.NONE_MSG, "")
     return msg
예제 #9
0
def signtx(transaction, key):
    """Sign a previously created transaction.

    TRANSACTION must be the hex encoded transaction, as for instance created
    using mktx or mkcontract. If it has already been signed before, its
    signature will be replaced.

    KEY must be the private key to sign with, in hexadecimal encoding or WIF.

    The signed transaction will be printed in hex encoding.
    """
    try:
        tx = Transaction.deserialize(str(transaction))
    except AssertionError:
        raise click.BadParameter('Unable to deserialize TRANSACTION.')
    tx.sign(encode_privkey(key, 'hex'))
    click.echo(tx.hex_serialize(True))
예제 #10
0
def signtx(transaction, key):
    """Sign a previously created transaction.

    TRANSACTION must be the hex encoded transaction, as for instance created
    using mktx or mkcontract. If it has already been signed before, its
    signature will be replaced.

    KEY must be the private key to sign with, in hexadecimal encoding or WIF.

    The signed transaction will be printed in hex encoding.
    """
    try:
        tx = Transaction.deserialize(str(transaction))
    except AssertionError:
        raise click.BadParameter('Unable to deserialize TRANSACTION.')
    tx.sign(encode_privkey(key, 'hex'))
    click.echo(tx.hex_serialize(True))
예제 #11
0
 def handle_miss(self, msg):
     log.info("------client handle_miss------")
     tx_pool = TxPool()
     txs = msg.get("data", {})
     for tx_data in txs:
         log.info("------server handle_miss: for------")
         tx = Transaction.deserialize(tx_data)
         is_new = True
         if tx_pool.is_new(tx):
             log.info("------client miss this transaction before------")
             bc = BlockChain()
             ls_bl = bc.get_last_block()
             log.info('------c handle_m ls_blo ' + str(ls_bl) + '------')
             if ls_bl:
                 ls_height = ls_bl.block_header.height
                 for i in range(0, ls_height + 1):
                     while True:
                         block = None
                         try:
                             block = bc.get_block_by_height(i)
                         except:
                             continue
                         if block:
                             break
                     bc_txs = block._transactions
                     if bc_txs:
                         for transaction in bc_txs:
                             if transaction.txid == tx.txid:
                                 log.info("------old transaction------")
                                 log.info("------the id is: " +
                                          str(tx.txid) + "------")
                                 is_new = False
                             else:
                                 log.info("------brand new miss------")
                                 log.info("------the id is: " +
                                          str(tx.txid) + "------")
                     if not is_new:
                         break
             if is_new:
                 tx_pool.add(tx)
                 log.info("------client miss add this transaction------")
                 log.info("------the id is: " + str(tx.txid) + "------")
                 log.info("------client handle_miss broadcast------")
     t = threading.Thread(target=self.shake_loop(), args=())
     t.start()
예제 #12
0
파일: network.py 프로젝트: ksl20200108/8.3
    def handle_transaction(self, msg):
        log.info("------client handle_transaction------")  # 7.8
        data = msg.get("data", {})
        tx = Transaction.deserialize(data)
        tx_pool = TxPool()
        is_new = True  # 7.20
        if tx_pool.is_new(tx):
            log.info(
                "------client never get this transaction before------")  # 7.20
            bc = BlockChain()
            ls_bl = bc.get_last_block()
            if ls_bl:
                ls_height = ls_bl.block_header.height
                for i in range(0, ls_height + 1):
                    while True:
                        block = None
                        try:
                            block = bc.get_block_by_height(i)
                        except:
                            continue
                        if block:
                            break
                    bc_txs = block._transactions
                    for transaction in bc_txs:
                        if transaction.txid == tx.txid:
                            is_new = False
                            break
                    if not is_new:
                        break
            if is_new:
                tx_pool.add(tx)
                log.info("------client handel_transaction txpool added------"
                         )  # 7.8
                server2 = PeerServer()
                server2.broadcast_tx(tx)
                log.info("------client handle_transaction broadcast------")

        msg = Msg(Msg.NONE_MSG, "")  # 7.23
        self.send(msg)  # 7.23
예제 #13
0
    def handle_transaction(self, msg):
        log.info("------client handle_transaction------")
        data = msg.get("data", {})
        tx = Transaction.deserialize(data)
        tx_pool = TxPool()
        is_new = True
        if tx_pool.is_new(tx):
            log.info("------client never get this transaction before------")
            bc = BlockChain()
            ls_bl = bc.get_last_block()
            log.info('------c handle_tran ls_blo ' + str(ls_bl) + '------')
            if ls_bl:
                ls_height = ls_bl.block_header.height
                for i in range(0, ls_height + 1):
                    while True:
                        block = None
                        try:
                            block = bc.get_block_by_height(i)
                        except:
                            continue
                        if block:
                            break
                    bc_txs = block._transactions
                    for transaction in bc_txs:
                        if transaction.txid == tx.txid:
                            is_new = False
                            break
                    if not is_new:
                        break
            if is_new:
                tx_pool.add(tx)
                log.info("------client handel_transaction txpool added------")
                server2 = PeerServer()
                server2.broadcast_tx(tx)
                log.info("------client handle_transaction broadcast------")

        t = threading.Thread(target=self.shake_loop(), args=())
        t.start()
예제 #14
0
def remote_transactions_received_handler(sender, transactions, **kwargs):
    "receives rlp.decoded serialized"
    txl = [Transaction.deserialize(rlp.encode(tx)) for tx in transactions]
    logger.debug('remote_transactions_received: %r', txl)
    for tx in txl:
        chain_manager.add_transaction(tx)
예제 #15
0
def remote_transactions_received_handler(sender, transactions, **kwargs):
    "receives rlp.decoded serialized"
    txl = [Transaction.deserialize(rlp.encode(tx)) for tx in transactions]
    logger.debug('remote_transactions_received: %r', txl)
    for tx in txl:
        chain_manager.add_transaction(tx)