Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from pybit.py3.chain import Chain
c = Chain(datStart=1,
verb=6,
defer_printing=0)
c.read_next_Dat()
print("b58: {0}".format(b58))
return b58
pk = "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522"\
+ "CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6"
addr = PK2Addr(pk,
debug=True)
assert addr == b'16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'
# %% Try using address in genesis block
# Import the first dat file
c = Chain(verb=4,
datStart=0,
datn=3)
c.read_next_Dat()
# Get the script from the first transaction in the first block
# (Assuming this is the genesis block!)
# Split off op_codes using split_scripts from Examples/DecodeOuputScripts.py
script = split_script(c.dats[0].blocks[0].trans[0].pkScript)
# Get the data to convert from after the push bytes op
pk = script[script.index("PUSH_BYTES")+2]
# Convert
addr = PK2Addr(pk,
debug=True)
# %% Read next block
# Read the block
dat.read_next_block()
# Verify it's correct (this may already have been done on import)
dat.blocks[0].api_verify()
# %% Print example transaction
dat.blocks[0].trans[0]._print()
# %% Read chain - 1 step
c = Chain(verb=2,
datStart=2)
c.read_next_Dat()
# -*- coding: utf-8 -*-
# %% Imports
from pybit.py3.chain import Chain
# %% Import a block
c = Chain(verb=1,
datStart=0,
datn=3)
c.read_next_Dat()
# %% Print the full transaction info of the only transaction in the genesis
# block
# All the output information is in .pkScript
c.dats[0].blocks[0].trans[0]._print()
# %% Function to split script in to components
def split_script(pk_op):
"""
# -*- coding: utf-8 -*-
# %% Imports
from pybit.py3.chain import Chain
# %% Create chain
c = Chain(verb=1,
datStart=0,
datn=1,
outputPath="ExportedBlocks/")
c.read_all()
from pybit.py3.chain import Chain, Dat
from pybit.py3.block_map import BlockMap
from pybit.pyx.utils import tqdm_off
# Optional import for pretty waitbars
try:
from tqdm import tqdm
print("Imported tqdm")
except ImportError:
tqdm = tqdm_off
# %% Higher level classes
class ChainMap(Chain):
def readDat(self, datn: int) -> Dat:
fn = "blk{0:05d}.dat".format(datn)
if self.verb >= 1:
print(f)
dat = DatMap(f,
verb=self.verb)
self.datni += 1
return dat
class DatMap(Dat):
def read_next_block(self,
n: int=1,
dat.blocks[0].trans[0].api_verify()
# %% Convert block transaction to pandas df
transTable = dat.trans_to_pandas()
transTable.head()
# %% Read chain - 1 step
"""
c = Chain(verb=4)
c.read_next_Dat()
"""
# %% Read chain - all (in range)
c = Chain(verb=1,
datStart=1,
datn=1)
c.read_all()
# %% Print example transaction
print(c.dats[1].blocks[2].trans[0])