Esempio n. 1
0
 def rebuild_template(self):
     """Rebuild a version 2 blockheader and serialize it.
         
        oldest satoshi client coinbase script contains:
            nBits, bnExtraNonce (nBits = GetNextWorkRequired(pindexPrev);)
        later timestamp was used instead of "bits" to ensure coinbase txn is unique even if address is the same (github:83f4cd156e9d52bd7c4351336dfa4806a43ee4e4=.
        now in version 2 blocks the height is included instead of the timestamp.
     """
     coinbase_script = Script(
         [push_bignum_instruction(self.block_height)] +
         [push_bignum_instruction(self.extra_nonce)] +
         [push_data_instruction(flag) for flag in self.coinbase_flags])
     coinbase_txin = TxIn(Outpoint.null(),
                          coinbase_script,
                          sequence=TxIn.NSEQUENCE_FINAL)
     coinbase_tx = Tx(version=1,
                      in_list=[coinbase_txin],
                      out_list=self.coinbase_txout_list,
                      locktime=0)
     self.block_transactions = [coinbase_tx] + self.transactions
     self.blockheader = BlockHeader(version=2,
                                    hash_prev=self.hash_prev,
                                    hash_merkle=compute_merkle_root(
                                        self.block_transactions),
                                    time=self.time,
                                    bits=self.bits,
                                    nonce=self.nonce)
     self.serialized = self.serializer.serialize(self.blockheader)
Esempio n. 2
0
 def rebuild_template(self):
     """Rebuild a version 2 blockheader and serialize it.
         
        oldest satoshi client coinbase script contains:
            nBits, bnExtraNonce (nBits = GetNextWorkRequired(pindexPrev);)
        later timestamp was used instead of "bits" to ensure coinbase txn is unique even if address is the same (github:83f4cd156e9d52bd7c4351336dfa4806a43ee4e4=.
        now in version 2 blocks the height is included instead of the timestamp.
     """
     coinbase_script = Script([push_bignum_instruction(self.block_height)] + 
                              [push_bignum_instruction(self.extra_nonce)] +
                              [push_data_instruction(flag) for flag in self.coinbase_flags])
     coinbase_txin = TxIn(Outpoint.null(),
                          coinbase_script,
                          sequence=TxIn.NSEQUENCE_FINAL)
     coinbase_tx = Tx(version=1,
                      in_list=[coinbase_txin],
                      out_list=self.coinbase_txout_list,
                      locktime=0)
     self.block_transactions = [coinbase_tx] + self.transactions
     self.blockheader = BlockHeader(version=2,
                               hash_prev=self.hash_prev,
                               hash_merkle=compute_merkle_root(self.block_transactions),
                               time=self.time,
                               bits=self.bits, 
                               nonce=self.nonce)
     self.serialized = self.serializer.serialize(self.blockheader)
def parse_instruction(inst_str):
    serializer = InstructionSerializer()
    if re.match("^-?[0-9]+$", inst_str):
        i = int(inst_str)
        if (i == -1 or (1 <=  i <= 16)):
            return serializer.serialize(Instruction(i + OP_1 - 1))
        else:
            return serializer.serialize(push_bignum_instruction(i))
        return serializer.serialize(push_bignum_instruction(i))
    if re.match("^'[^']*'$", inst_str):
        return serializer.serialize(push_data_instruction(str(inst_str[1:-1])))
    elif re.match("^0x[0-9A-Fa-f]+$", inst_str):
        return decodehexstr(inst_str[2:])
    elif inst_str in OPCODES_BY_NAME:
        return serializer.serialize(Instruction(OPCODES_BY_NAME[inst_str]))
    elif ("OP_" + inst_str) in OPCODES_BY_NAME:
        return serializer.serialize(Instruction(OPCODES_BY_NAME["OP_" + inst_str]))
    raise Exception("Wrong format: '" + inst_str + "'")
Esempio n. 4
0
def parse_instruction(inst_str):
    serializer = InstructionSerializer()
    if re.match("^-?[0-9]+$", inst_str):
        i = int(inst_str)
        if (i == -1 or (1 <= i <= 16)):
            return serializer.serialize(Instruction(i + OP_1 - 1))
        else:
            return serializer.serialize(push_bignum_instruction(i))
        return serializer.serialize(push_bignum_instruction(i))
    if re.match("^'[^']*'$", inst_str):
        return serializer.serialize(push_data_instruction(str(inst_str[1:-1])))
    elif re.match("^0x[0-9A-Fa-f]+$", inst_str):
        return decodehexstr(inst_str[2:])
    elif inst_str in OPCODES_BY_NAME:
        return serializer.serialize(Instruction(OPCODES_BY_NAME[inst_str]))
    elif ("OP_" + inst_str) in OPCODES_BY_NAME:
        return serializer.serialize(
            Instruction(OPCODES_BY_NAME["OP_" + inst_str]))
    raise Exception("Wrong format: '" + inst_str + "'")
Esempio n. 5
0
from coinpy.model.protocol.runmode import MAIN, TESTNET, TESTNET3, UNITNET
from coinpy.lib.vm.script.push_data import push_bignum_instruction,\
    push_data_instruction
from coinpy.lib.transactions.merkle_tree import compute_merkle_root
from coinpy.lib.serialization.scripts.serialize import ScriptSerializer

GENESIS_MAIN =  Block(
    BlockHeader(1, 
                Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), #hash_prev
                Uint256.from_hexstr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"), #merkle
                1231006505,  #time
                486604799,   #bits
                2083236893), #nonce
    [Tx(1, #version
        [TxIn(Outpoint(Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), 4294967295),     
                Script([push_bignum_instruction(486604799), #bits
                        push_bignum_instruction(4), #extra_nonce
                        push_data_instruction("The Times 03/Jan/2009 Chancellor on brink of second bailout for banks")]), #script
                4294967295) ], #inlist
        [TxOut(5000000000, #value
                Script([push_data_instruction(decodehexstr("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")),Instruction(OP_CHECKSIG)]))],
                0) #locktime         
     ])

GENESIS_TESTNET =  Block(
    BlockHeader(1, 
                Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), #hash_prev
                Uint256.from_hexstr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"), #merkle
                1296688602,  #time
                487063544,   #bits
                384568319), #nonce