class Input(ormin.Model): in_pos = ormin.IntField() coinbase = ormin.StringField(required=False) txid = ormin.StringField(required=False) vout = ormin.IntField(required=False) scriptsig_asm = ormin.TextField(required=False) scriptsig_hex = ormin.TextField(required=False) scriptwitness = ormin.BlobField(required=False) pegin_witness = ormin.BlobField(required=False) sequence = ormin.BigIntField(required=False) def __init__(self, json_dict=None, *args, **kwargs): if 'scriptWitness' in json_dict: json_dict['scriptwitness'] = json.dumps(json_dict['scriptWitness']) if 'pegin_witness' in json_dict: json_dict['pegin_witness'] = json_dict['pegin_witness'] if 'scriptSig' in json_dict: json_dict['scriptsig_asm'] = json_dict['scriptSig']['asm'] json_dict['scriptsig_hex'] = json_dict['scriptSig']['hex'] super(Input, self).__init__(json_dict=json_dict, *args, **kwargs) def new_id(self): self.id = "%s_%s" % (self.tx_id, self.in_pos)
class Chaininfo(RpcCachedModel): bestblockhash = ormin.StringField() blocks = ormin.IntField() mediantime = ormin.IntField() cached_blocks = ormin.IntField() caching_first = ormin.IntField() caching_blockhash = ormin.StringField() caching_last = ormin.IntField() signblock_asm = ormin.StringField(required=False) signblock_hex = ormin.StringField(required=False) @classmethod def truth_src_get(cls, req_id): json_result = super(Chaininfo, cls)._rpccaller.RpcCall('getblockchaininfo', {}) if 'error' in json_result: return json_result chaininfo = cls(json_dict=json_result) chaininfo.id = req_id chaininfo.start_caching_progress() chaininfo.save() return chaininfo def clean_caching_progress_fields(self): self.caching_first = -1 self.caching_blockhash = '' self.caching_last = -1 def start_caching_progress(self): self.cached_blocks = -1 self.clean_caching_progress_fields()
class Block(RpcCachedModel): height = ormin.IntField(index=True, unique=True) previousblockhash = ormin.StringField(index=True, required=False) # For chains with pow (optional) bits = ormin.StringField(required=False) chainwork = ormin.StringField(required=False) difficulty = ormin.BigIntField(required=False) nonce = ormin.BigIntField(required=False) # For chains with signed blocks (optional) signblock_witness_asm = ormin.StringField(required=False) signblock_witness_hex = ormin.StringField(required=False) mediantime = ormin.IntField() merkleroot = ormin.StringField() size = ormin.IntField() # strippedsize = ormin.IntField() time = ormin.IntField() # version = ormin.IntField() # versionhex = ormin.StringField() weight = ormin.IntField() tx = ormin.BlobField() @classmethod def truth_src_get(cls, req_id): json_result = super(Block, cls)._rpccaller.RpcCall('getblock', {'blockhash': req_id}) if 'error' in json_result: return json_result block = Block(json_dict=json_result) block.id = req_id block.save() return block
class Tx(RpcCachedModel): blockhash = ormin.StringField(index=True) time = ormin.IntField(required=False) hex = ormin.TextField() size = ormin.IntField() vsize = ormin.IntField() version = ormin.IntField() locktime = ormin.BigIntField() vin = ormin.OneToManyField(Input, 'tx_id', cascade=True) vout = ormin.OneToManyField(Output, 'tx_id', cascade=True) @classmethod def truth_src_get(cls, req_id): json_result = super(Tx, cls)._rpccaller.RpcCall('getrawtransaction', { 'txid': req_id, 'verbose': 1 }) if 'error' in json_result: return json_result # TODO Return this from the daemons? # Even if the numbers were wrong due to json non-specified "magic", # we should be fine since this is only needed for guaranteeing # a unique id for inputs for it in xrange(len(json_result['vin'])): json_result['vin'][it]['in_pos'] = it tx = Tx(json_dict=json_result) tx.id = req_id # Don't cache mempool txs if 'blockhash' in json_result and json_result['blockhash']: tx.save() return tx
class Block(ormin.Model): height = ormin.IntField(index=True) blob = ormin.TextField()
class Chaininfo(ormin.Model): bestblockhash = ormin.StringField() blocks = ormin.IntField() mediantime = ormin.IntField()
class Mempoolstats(ormin.Model): time = ormin.IntField(index=True) blob = ormin.TextField()
class Output(ormin.Model): n = ormin.IntField() value = ormin.StringField(required=False) value_minimum = ormin.StringField(required=False) value_maximum = ormin.StringField(required=False) ct_exponent = ormin.StringField(required=False) ct_bits = ormin.StringField(required=False) asset = ormin.StringField(required=False) assetcommitment = ormin.StringField(required=False) amountcommitment = ormin.StringField(required=False) scriptpubkey_asm = ormin.TextField() scriptpubkey_hex = ormin.TextField() scriptpubkey_type = ormin.StringField() scriptpubkey_reqsigs = ormin.IntField(required=False) scriptpubkey_addresses = ormin.BlobField(required=False) pegout_chain = ormin.StringField(required=False) pegout_scriptpubkey_asm = ormin.TextField(required=False) pegout_scriptpubkey_hex = ormin.TextField(required=False) pegout_scriptpubkey_type = ormin.StringField(required=False) pegout_scriptpubkey_reqsigs = ormin.IntField(required=False) pegout_scriptpubkey_addresses = ormin.BlobField(required=False) def __init__(self, json_dict=None, *args, **kwargs): if 'value-minimum' in json_dict: json_dict['value_minimum'] = json_dict['value-minimum'] if 'value-maximum' in json_dict: json_dict['value_maximum'] = json_dict['value-maximum'] if 'ct-exponent' in json_dict: json_dict['ct_exponent'] = json_dict['ct-exponent'] if 'ct-bits' in json_dict: json_dict['ct_bits'] = json_dict['ct-bits'] if 'scriptPubKey' in json_dict: json_dict['scriptpubkey_asm'] = json_dict['scriptPubKey']['asm'] json_dict['scriptpubkey_hex'] = json_dict['scriptPubKey']['hex'] json_dict['scriptpubkey_type'] = json_dict['scriptPubKey']['type'] if 'reqSigs' in json_dict['scriptPubKey']: json_dict['scriptpubkey_reqsigs'] = json_dict['scriptPubKey'][ 'reqSigs'] if 'addresses' in json_dict['scriptPubKey']: json_dict['scriptpubkey_addresses'] = json.dumps( json_dict['scriptPubKey']['addresses']) if 'pegout_asm' in json_dict['scriptPubKey']: json_dict['pegout_scriptpubkey_asm'] = json_dict[ 'scriptPubKey']['pegout_asm'] if 'pegout_hex' in json_dict['scriptPubKey']: json_dict['pegout_scriptpubkey_hex'] = json_dict[ 'scriptPubKey']['pegout_hex'] if 'pegout_type' in json_dict['scriptPubKey']: json_dict['pegout_scriptpubkey_type'] = json_dict[ 'scriptPubKey']['pegout_type'] if 'pegout_reqSigs' in json_dict['scriptPubKey']: json_dict['pegout_scriptpubkey_reqsigs'] = json_dict[ 'scriptPubKey']['pegout_reqSigs'] if 'pegout_addresses' in json_dict['scriptPubKey']: json_dict['pegout_scriptpubkey_addresses'] = json.dumps( json_dict['scriptPubKey']['pegout_addresses']) super(Output, self).__init__(json_dict=json_dict, *args, **kwargs) def new_id(self): self.id = "%s_%s" % (self.tx_id, self.n)