Compare commits
1 Commits
883a931495
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
b8ee1ed97d |
10
CHANGELOG
10
CHANGELOG
@ -1,13 +1,3 @@
|
|||||||
- 0.2.0
|
|
||||||
* Consolidate genertic blcok, tx and tx result objects
|
|
||||||
- 0.1.3
|
|
||||||
* Remove superfluous arguments for chain settings instantiation
|
|
||||||
- 0.1.2
|
|
||||||
* Upgrade hexathon dep
|
|
||||||
- 0.1.1
|
|
||||||
* Add settings object
|
|
||||||
- 0.1.0
|
|
||||||
* Upgrade deps
|
|
||||||
- 0.0.23
|
- 0.0.23
|
||||||
* Configuration variable descriptions
|
* Configuration variable descriptions
|
||||||
* Arg flags to names listing method
|
* Arg flags to names listing method
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
import enum
|
import enum
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from .tx import Tx
|
from chainlib.tx import Tx
|
||||||
from .src import Src
|
|
||||||
|
|
||||||
|
|
||||||
class BlockSpec(enum.IntEnum):
|
class BlockSpec(enum.IntEnum):
|
||||||
@ -13,24 +12,23 @@ class BlockSpec(enum.IntEnum):
|
|||||||
LATEST = 0
|
LATEST = 0
|
||||||
|
|
||||||
|
|
||||||
class Block(Src):
|
class Block:
|
||||||
"""Base class to extend for implementation specific block object.
|
"""Base class to extend for implementation specific block object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tx_generator = Tx
|
tx_generator = Tx
|
||||||
|
|
||||||
def __init__(self, src):
|
|
||||||
self.number = None
|
|
||||||
self.txs = []
|
|
||||||
self.author = None
|
|
||||||
|
|
||||||
self.get_tx = self.tx_index_by_hash
|
def src(self):
|
||||||
self.tx = self.tx_by_index
|
"""Return implementation specific block representation.
|
||||||
|
|
||||||
super(Block, self).__init__(src)
|
:rtype: dict
|
||||||
|
:returns: Block representation
|
||||||
|
"""
|
||||||
|
return self.block_src
|
||||||
|
|
||||||
|
|
||||||
def tx_by_index(self, idx):
|
def tx(self, idx):
|
||||||
"""Return transaction object for transaction data at given index.
|
"""Return transaction object for transaction data at given index.
|
||||||
|
|
||||||
:param idx: Transaction index
|
:param idx: Transaction index
|
||||||
@ -41,24 +39,28 @@ class Block(Src):
|
|||||||
return self.tx_generator(self.txs[idx], self)
|
return self.tx_generator(self.txs[idx], self)
|
||||||
|
|
||||||
|
|
||||||
def tx_index_by_hash(self, hsh):
|
def tx_src(self, idx):
|
||||||
for tx in self.tx:
|
"""Return implementation specific transaction representation for transaction data at given index
|
||||||
if tx == hsh:
|
|
||||||
return tx
|
|
||||||
return -1
|
|
||||||
|
|
||||||
#
|
:param idx: Transaction index
|
||||||
#
|
:type idx: int
|
||||||
# def tx_src(self, idx):
|
:rtype: chainlib.tx.Tx
|
||||||
# """Return implementation specific transaction representation for transaction data at given index
|
:returns: Transaction representation
|
||||||
#
|
"""
|
||||||
# :param idx: Transaction index
|
return self.txs[idx]
|
||||||
# :type idx: int
|
|
||||||
# :rtype: chainlib.tx.Tx
|
|
||||||
# :returns: Transaction representation
|
|
||||||
# """
|
|
||||||
# return self.txs[idx]
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'block {} {} ({} txs)'.format(self.number, self.hash, len(self.txs))
|
return 'block {} {} ({} txs)'.format(self.number, self.hash, len(self.txs))
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_src(cls, src):
|
||||||
|
"""Instantiate an implementation specific block object from the given block representation.
|
||||||
|
|
||||||
|
:param src: Block representation
|
||||||
|
:type src: dict
|
||||||
|
:rtype: chainlib.block.Block
|
||||||
|
:returns: Block object
|
||||||
|
"""
|
||||||
|
return cls(src)
|
||||||
|
@ -4,7 +4,7 @@ from .chain import ChainSpec
|
|||||||
|
|
||||||
class ChainSettings:
|
class ChainSettings:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, include_sync=False, include_queue=False):
|
||||||
self.o = {}
|
self.o = {}
|
||||||
self.get = self.o.get
|
self.get = self.o.get
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import enum
|
|||||||
class Status(enum.Enum):
|
class Status(enum.Enum):
|
||||||
"""Representation of transaction status in network.
|
"""Representation of transaction status in network.
|
||||||
"""
|
"""
|
||||||
UNKNOWN = -1
|
|
||||||
PENDING = 0
|
PENDING = 0
|
||||||
SUCCESS = 1
|
SUCCESS = 1
|
||||||
ERROR = 2
|
ERROR = 2
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
# local imports
|
class Tx:
|
||||||
from .status import Status
|
|
||||||
from .src import Src
|
|
||||||
|
|
||||||
|
|
||||||
class Tx(Src):
|
|
||||||
"""Base class to extend for implementation specific transaction objects.
|
"""Base class to extend for implementation specific transaction objects.
|
||||||
|
|
||||||
:param src: Transaction representation source
|
:param src: Transaction representation source
|
||||||
@ -12,73 +7,8 @@ class Tx(Src):
|
|||||||
:type block: chainlib.block.Block
|
:type block: chainlib.block.Block
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, src=None, block=None, result=None, strict=False):
|
def __init__(self, src, block=None):
|
||||||
|
self.src = src
|
||||||
self.block = block
|
self.block = block
|
||||||
self.index = -1
|
self.block_src = None
|
||||||
|
self.index = None
|
||||||
self.fee_limit = None
|
|
||||||
self.fee_price = None
|
|
||||||
|
|
||||||
self.nonce = None
|
|
||||||
self.value = 0
|
|
||||||
|
|
||||||
self.outputs = []
|
|
||||||
self.inputs = []
|
|
||||||
self.payload = None
|
|
||||||
|
|
||||||
self.result = None
|
|
||||||
|
|
||||||
self.generate_wire = self.wire
|
|
||||||
|
|
||||||
super(Tx, self).__init__(src)
|
|
||||||
|
|
||||||
if block != None:
|
|
||||||
self.apply_block(block)
|
|
||||||
|
|
||||||
if result != None:
|
|
||||||
self.apply_result(result)
|
|
||||||
|
|
||||||
|
|
||||||
def apply_result(self, result):
|
|
||||||
self.result = result
|
|
||||||
|
|
||||||
|
|
||||||
def apply_block(self, block):
|
|
||||||
self.block = block
|
|
||||||
|
|
||||||
|
|
||||||
def status(self):
|
|
||||||
if self.result == None:
|
|
||||||
return None
|
|
||||||
return self.result.status
|
|
||||||
|
|
||||||
|
|
||||||
def status_name(self):
|
|
||||||
if self.result == None:
|
|
||||||
return None
|
|
||||||
return self.result.status.name
|
|
||||||
|
|
||||||
|
|
||||||
def wire(self):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
|
||||||
def as_dict(self):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
if self.block != None:
|
|
||||||
return 'tx {} status {} block {} index {}'.format(self.display_hash(), self.status_name(), self.block.number, self.index)
|
|
||||||
else:
|
|
||||||
return 'tx {} status {}'.format(self.display_hash(), self.hash, self.status_name())
|
|
||||||
|
|
||||||
|
|
||||||
class TxResult(Src):
|
|
||||||
|
|
||||||
def __init__(self, src):
|
|
||||||
self.status = Status.UNKNOWN
|
|
||||||
self.tx_index = None
|
|
||||||
self.block_hash = None
|
|
||||||
self.fee_cost = 0
|
|
||||||
super(TxResult, self).__init__(src=src)
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
funga~=0.5.2
|
funga~=0.5.2
|
||||||
pysha3==1.0.2
|
pysha3==1.0.2
|
||||||
hexathon~=0.1.7
|
hexathon~=0.1.5
|
||||||
confini~=0.6.0
|
confini~=0.6.0
|
||||||
|
@ -3,7 +3,7 @@ name=chainlib
|
|||||||
license=WTFPL2
|
license=WTFPL2
|
||||||
author_email=dev@holbrook.no
|
author_email=dev@holbrook.no
|
||||||
description=Generic blockchain access library and tooling
|
description=Generic blockchain access library and tooling
|
||||||
version=0.2.0
|
version=0.1.1
|
||||||
url=https://gitlab.com/chaintools/chainlib
|
url=https://gitlab.com/chaintools/chainlib
|
||||||
author=Louis Holbrook
|
author=Louis Holbrook
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user