Beispiel #1
0
 def create_coinbase(cls, pay_to_addr, value, height):
     """
     Only mining can create a new block with first tx is coinbase.
     """
     return cls(
         txins=[
             TxIn(
                 to_spend=None,
                 # Push current block height into unlock_sig so that this
                 # transaction's ID is unique relative to other coinbase txns.
                 # first param is unlock_sig, another is unlock_pk
                 signature_script=scriptBuild.
                 get_signature_script_without_hashtype(
                     str(height).encode(), b"") if Params.SCRIPT_TYPE == 0
                 else scriptBuild.get_signature_script_without_hashtype(
                     [str(height).encode()], b""),
                 sequence=0,
             )
         ],
         txouts=[
             TxOut(value=value,
                   pk_script=scriptBuild.get_pk_script(pay_to_addr))
         ],
         serviceId=None,
         actionId=None,
         postId=None,
         data=None,
         locktime=None,
     )
Beispiel #2
0
 def genesis_block(cls):
     return cls(
         version=
         '5465616d3a20456467656e63650a4c65616465723a20776f6c6662726f746865720a4d656d626572733a2063626f7a69'
         '2c204c6561684c69752c207069616f6c69616e676b622c2053616c7661746f7265303632362c2053696c7669614c69313'
         '232352c204a69617169204c69752c2078696179756e696c0a',
         prev_block_hash=None,
         merkle_hash=
         '8cfb8d2d2ed9343461b0eefb73c775b9366a32e05e81b0e8946620e2f1935507',
         timestamp=1554460209,
         bits=Params.INITIAL_DIFFICULTY_BITS,
         nonce=17040052,
         txns=[
             Transaction(
                 txins=[
                     TxIn(to_spend=None,
                          unlock_sig=b'0',
                          unlock_pk=None,
                          sequence=0)
                 ],
                 txouts=[
                     TxOut(value=5000000000,
                           to_address='0000000000000000000000000000000000')
                 ],
                 locktime=None)
         ])
Beispiel #3
0
 def genesis_block(cls):
     return cls(
         version="5465616d3a20456467656e63650a4c65616465723a20776f6c6662726f746865720a4d656d626572733a2063626f7a69"
         "2c204c6561684c69752c207069616f6c69616e676b622c2053616c7661746f7265303632362c2053696c7669614c69313"
         "232352c204a69617169204c69752c2078696179756e696c0a",
         prev_block_hash=None,
         merkle_hash="a578b7a3bdc2d1385bce32a445a8ec4ffb9ab78b76afc30f53787b3189be289c",
         timestamp=1554460209,
         bits=Params.INITIAL_DIFFICULTY_BITS,
         nonce=41912381,
         txns=[
             Transaction(
                 txins=[TxIn(to_spend=None, signature_script=b"0", sequence=0)],
                 txouts=[
                     TxOut(
                         value=5000000000,
                         pk_script=scriptBuild.get_pk_script(
                             "1NY36FKZqM97oEobfCewhUpHsbzAUSifzo"
                         ),
                     )
                 ],
                 locktime=None,
                 serviceId=None,
                 postId=None,
                 actionId=None,
                 data=None,
             )
         ],
     )
Beispiel #4
0
    def _makeTxin(self, txinType, outpoint: OutPoint, txout) -> TxIn:
        def build_spend_message(to_spend, pk, sequence, txouts):

            spend_msg = Utils.sha256d(
                Utils.serialize(to_spend) + str(sequence) +
                binascii.hexlify(pk).decode() +
                Utils.serialize(txouts)).encode()

            return spend_msg

        sequence = 0

        if txinType == 0:
            logger.info(f'[EdgeHand] make txn with P2PKH txnIn')
            # get public key
            pk = self.wallet.signing_key.verifying_key.to_string()
            # get signature
            spend_msg = build_spend_message(outpoint, pk, sequence, txout)
            # use private key to sign the data for the first time
            signature = self.wallet.signing_key.sign(spend_msg)
            return TxIn(to_spend=outpoint,
                        signature_script=self._make_signature_script(
                            txinType, signature, pk),
                        sequence=sequence)

        elif txinType == 1:
            logger.info(f'[EdgeHand] make txn with P2PSH txnIn')
            # check the len of key pairs
            if len(self.wallet.keypairs) != Params.P2SH_PUBLIC_KEY:
                raise Exception("KeyPair length wrong")
            pk = [
                key.verifying_key.to_string() for key in self.wallet.keypairs
            ]
            redeem_script = scriptBuild.get_redeem_script(pk)
            # get sig as much as the nums of len(pk)-1 in order
            signature = [
                self.wallet.keypairs[i].sign(
                    build_spend_message(outpoint, pk[i], sequence, txout))
                for i in range(len(pk)) if i < (len(pk) - 1)
            ]
            return TxIn(to_spend=outpoint,
                        signature_script=self._make_signature_script(
                            txinType, signature, redeem_script),
                        sequence=sequence)
        else:
            raise Exception("Can't get right Param.script_type!")
Beispiel #5
0
 def create_coinbase(cls, pay_to_addr, value, height):
     return cls(
         txins=[
             TxIn(
                 to_spend=None,
                 # Push current block height into unlock_sig so that this
                 # transaction's ID is unique relative to other coinbase txns.
                 unlock_sig=str(height).encode(),
                 unlock_pk=None,
                 sequence=0)
         ],
         txouts=[TxOut(value=value, to_address=pay_to_addr)],
     )
Beispiel #6
0
 def create_coinbase(cls, pay_to_addr, value, height):
     return cls(
         txins=[
             TxIn(
                 to_spend=None,
                 # Push current block height into unlock_sig so that this
                 # transaction's ID is unique relative to other coinbase txns.
                 # first param is unlock_sig, another is unlock_pk
                 signature_script=scriptBuild.
                 get_signature_script_without_hashtype(
                     str(height).encode(), b'') if Params.SCRIPT_TYPE == 0
                 else scriptBuild.get_signature_script_without_hashtype(
                     [str(height).encode()], b''),
                 sequence=0)
         ],
         txouts=[
             TxOut(value=value,
                   pk_script=scriptBuild.get_pk_script(pay_to_addr))
         ],
     )
Beispiel #7
0
 def genesis_block(cls):
     return cls(
         version=
         '5465616d3a20456467656e63650a4c65616465723a20776f6c6662726f746865720a4d656d626572733a2063626f7a69'
         '2c204c6561684c69752c207069616f6c69616e676b622c2053616c7661746f7265303632362c2053696c7669614c69313'
         '232352c204a69617169204c69752c2078696179756e696c0a',
         prev_block_hash=None,
         merkle_hash=
         'b7b51d3818055321711cf3049b7067afb7d5cbddacc6c106ca92906974316b14',
         timestamp=1554460209,
         bits=Params.INITIAL_DIFFICULTY_BITS,
         nonce=5808524,
         txns=[
             Transaction(txins=[
                 TxIn(to_spend=None, signature_script=b'0', sequence=0)
             ],
                         txouts=[
                             TxOut(
                                 value=5000000000,
                                 pk_script=scriptBuild.get_pk_script(
                                     '1NY36FKZqM97oEobfCewhUpHsbzAUSifzo'))
                         ],
                         locktime=None)
         ])
Beispiel #8
0
from ds.Transaction import Transaction
from ds.MerkleNode import MerkleNode
from ds.TxIn import TxIn
from ds.TxOut import TxOut
from ds.Block import Block
from consensus.Consensus import PoW
from params.Params import Params
from script import scriptBuild
from utils.Utils import Utils

import time


txns = [
    Transaction(
        txins=[TxIn(to_spend=None, signature_script=b"0", sequence=0)],
        txouts=[
            TxOut(
                value=5000000000,
                pk_script=scriptBuild.get_pk_script(
                    "1NY36FKZqM97oEobfCewhUpHsbzAUSifzo"
                ),
            )
        ],
        serviceId=None,
        postId=None,
        actionId=None,
        data=None,
        locktime=None,
    )
]