The Cellframe.Chain module is designed to work with chains. This module includes the following classes:
CellFrame.Chain.Chain
A chain class.CellFrame.Chain.ChainType
A chain type class.CellFrame.Chain.ChainAtomIter
An atom iterator class.CellFrame.Chain.ChainAtomPtr
An atom pointer class.CellFrame.Chain.ChainCell
An cell class.CellFrame.Chain.ChainID
A chain ID class.CellFrame.Chain.ChainCellID
A cell ID class.CellFrame.Chain.ChainHashSlow
An hash class.CellFrame.Chain.ChainHashSlowKind
An kind of hash class.CellFrame.Chain.ChainID
A chain address class.CellFrame.Chain.ChainCS
A chain consensus class.CellFrame.Chain.GlobalDB
A class for handling a global databaseCellFrame.Chain.Wallet
A class for handling wallets.CellFrame.Chain.Mempool
A class for hamdling a mempool.CellFrame.Chain.Ledger
A class for hamdling a ledger.class CellFrame.Chain.Chain
This class provides methods for working with a chain.
staic method CellFrame.Chain.Chain.findById(netId: CellFrame.Chain.NetID, chainId: CellFrame.Chain.ChainID) -> CellFrame.Chain.Chain
Finds a chain by the netId
and the chainId
and returns the instance of Chain
class.
static method CellFrame.Chain.Chain.loadFromCfg(ledger: CellFrame.Chain.Ledger, netName: str, netId: CellFrame.Chain.NetID, cfgName: str) -> CellFrame.Chain.Chain
Loads chain from configuration. The ledger
argument is instance of CellFrame.Chain.Ledger
class. The netName
is a chain name, taken from configuration, for example, "home21-network". The netId
is chain network identification. And the cfgName
is a chain configuration name, for example, "network/home21-network/chain-0". Returns the instance of Chain
class.
object method CellFrame.Chain.Chain.hasFileStore() -> bool
Returns True
if the file storage path is set in the instance, otherwise False
.
object method CellFrame.Chain.Chain.saveAll() -> int
Saves all nested cells. Returns a number of the saved cells.
object method CellFrame.Chain.Chain.loadAll() -> int
Loads all nested cells. Returns a number of the loaded cells.
object method CellFrame.Chain.Chain.createAtomItem() -> CellFrame.Chain.ChainAtomIter
Creates a new atom iterator. Returns an instance of a ChainAtomIter
object.
object method CellFrame.Chain.Chain.atomIterGetFirst(iter: CellFrame.Chain.ChainAtomIter) -> tuple(CellFrame.Chain.ChainAtomPtr, atomSize: int)
Gets the first atom and a size of the atom. Returns a tuple consisting of an instance of a ChainAtomPtr
object and a size of atom or None
.
object method CellFrame.Chain.atomGetDatums(atom: CellFrame.Chain.ChainAtomPtr, atomSize: int) -> List[CellFrame.Common.ChainDatum]
Gets datums of an atom. Returns a list of ChainDatum
objects.
object method CellFrame.Chain.Chain.atomIterGetNext(iter: CellFrame.Chain.ChainAtomIter) -> tuple(CellFrame.ChainAtomPtr, atomSize: int)
Gets a next atom. Returns a tuple consisting of an instance of a ChainAtomPtr
object and a size of atom or (None, 0)
.
object method CellFrame.Chain.Chain.getDag() -> CellFrame.Chain.ChainCsDag
Gets a DAG. Returns an instance of a ChainCsDag
object.
object method CellFrame.Chain.Chain.addAtomNotify(atomNotify: callable, arg: object) -> None
Adds an atom notify. The atomNotify
function must have f(atom: CellFrame.Chain.ChainAtomPtr, arg: object)
signature. The atom
can be None
.
(Added in version 5.2)
object method CellFrame.Chain.Chain.addMempoolNotify(mempoolNotify: callable, arg: object) -> CellFrame.Chain.ChainCsDag
Adds a mempool notify. The mempoolNotify
function must have f(opcode: str, group: str, key: str, value: bytes, arg: object)
signature.
object method CellFrame.Chain.countTx() -> int
Gets a count of transaction. Returns an integer value.
object method CellFrame.Chain.Chain.getTransactions() -> List[CellFrame.Common.ChainDatumTx]
Gets transactions. Returns a list of CellFrame.ChainDatumTx
objects.
class CellFrame.Chain.ChainType
This class is designed to work with the type of a chain. Using the following static functions, you can generate the required type.
static method CellFrame.Chain.ChainType.CHAIN_TYPE_FIRST() -> CellFrame.Chain.ChainType
Returns the first chain type.
static method CellFrame.Chain.ChainType.CHAIN_TYPE_TOKEN() -> CellFrame.Chain.ChainType
Returns the token chain type.
static method CellFrame.Chain.ChainType.CHAIN_TYPE_EMISSION() -> CellFrame.Chain.ChainType
Returns the emission chain type.
static method CellFrame.Chain.ChainType.CHAIN_TYPE_TX() -> CellFrame.Chain.ChainType
Returns the tx chain type.
static method CellFrame.Chain.ChainType.CHAIN_TYPE_LAST() -> CellFrame.Chain.ChainType
Returns the last chain type.
class CellFrame.Chain.ChainAtomIter
This class is atomic element iterator. This class has no methods and attributes.
class CellFrame.Chain.ChainAtomPtr
This class is atomic pointer. This class has no methods and attributes.
class CellFrame.Chain.ChainCell
This class is chain cell object.
static method CellFrame.Chain.ChainCell.load(chain: CellFrame.Chain.Chain, cellFilePath: str) -> int
Loads cell states from a file. The cellFilePath
is the absolute path to the cell file. Returns 0
if loaded all atoms, otherwise an error code less than zero.
object method CellFrame.Chain.ChainCell.update() -> int
Updates the cell file. Returns 0
if successful, otherwise an error code less than zero.
object method CellFrame.Chain.ChainCell.append(atom: bytes, atomSize: int ) -> int
Adds atoms to the chain. Returns 0
if successful, otherwise an error code less than zero.
class CellFrame.Chain.ChainlID
This class is chain ID object. This class has no methods and attributes.
The str(obj: CellFrame.Chain.ChainID)
operation returns a string version of object.
class CellFrame.Chain.ChainCellID
This class is chain cell ID object. This class has no methods and attributes.
The str(obj: CellFrame.Chain.ChainCellID)
operation returns a string version of object.
class CellFrame.Chain.ChainHashSlow
This class is chain hash slow object.
static method CellFrame.Chain.ChainHashSlow.toStr(hashSlow: CellFrame.Chain.ChainHashSlow, string: str, strMax: int) -> (int, str)
Converts a hash to a string.
class CellFrame.Chain.ChainHashSlowKind
This class is a kind of a hash object. This class has no methods and attributes.
class CellFrame.Chain.ChainAddr
This class implements the chain address object.
object method CellFrame.Chain.ChainAddr.toStr(chainAddr: CellFrame.Chain.ChainAddr) -> str
Converts to a string.
static method CellFrame.Chain.ChainAddr.fromStr(string: str) -> CellFrame.Chain.ChainAddr
Converts ф string to a ChainAddr
object.
static method CellFrame.Chain.ChainAddr.fill(signType: DAP.Crypto.SignType, pkeyHash: DAP.Crypto.HashFast, netId: CellFrame.Network.ChainNetID) -> CellFrame.Chain.ChainAddr
Fills an address from the key
and netId
. Returns an instance of itself.
object method CellFrame.Chain.ChainAddr.fill(key: DAP.CryptoKey, netId: CellFrame.ChainNetID) -> CellFrame.ChainAddr
Fills an address from the key
and netId
. Returns an instance of itself.
object method CellFrame.Chain.ChainAddr.checkSum() -> int
Checks if checksum is correct. Return 1
if it is, otherwise 0
.
object method CellFrame.Chain.ChainAddr.getNetId() -> CellFrame.ChainNetID
Gets a CellFrame.ChainNetID
object.
class CellFrame.Chain.ChainCS
This class is chain cs object.
object method CellFrame.Chain.ChainAddr.csAdd(csName: str, callBackFunc: callable) -> int
Adds a consensus. The csName
is a consensus name ("dag_pos", "dag_poa", "block_poa", "none"), the callBackFunc
is a callback function of signature f(chain: CellFrame.Chain.Chain) -> int
. Returns 0 if successful.
object method CellFrame.Chain.ChainAddr.csCreate(chain: CellFrame.Chain.Chain) -> int
Creates a consensus from the configuration specified in the Cellframe.init
function or in the configuration file. Verifies if consensus was created by CellFrame.Chain.ChainAddr.csAdd
function. Returns 0
if successful, otherwise an error code less than 0
.
object method CellFrame.Chain.ChainAddr.classAdd(csName: str, callBackFunc: callable) -> int
Adds a class. The csName
is a consensus name ("dag_pos", "dag_poa", "block_poa", "none"), the callBackFunc
is a callback function of type f(chain: CellFrame.Chain) -> int
. Returns 0 if successful.
object method CellFrame.Chain.ChainAddr.classCreate(chain: CellFrame.Chain) -> int
Creates a class from the configuration specified in the Cellframe.init
function or in the configuration file. Verifies if consensus was created by CellFrame.ChainAddr.csAdd
function. Returns 0
if successful, otherwise an error code less than 0
.
class CellFrame.Chain.GlobalDB
This class provides methods for working with a global database.
static method CellFrame.Chain.GlobalDB.get(key: str, group: str) -> bytes
Reads data from a database by a key and a group. Returns a bytes if successful.
static method CellFrame.Chain.GlobalDB.set(key: str, group: str, data: bytes) -> boolean
Writes data to a database by a key and a group. Returns True
if data has been written, otherwise False
.
static method CellFrame.Chain.GlobalDB.delete(key: str, group: str) -> boolean
Deletes data in a database by a key and a group. Returns True
if data has been deleted, otherwise False
.
static method CellFrame.Chain.GlobalDB.pin() -> None
Not implemented yet.
class CellFrame.Chain.Wallet
This class provides working with a wallet.
constructor CellFrame.Chain.Wallet(name: str, path: str, signType: DAP.Crypto.SignType)
Creates an instance of a Wallet
object. The name
is a wallet name. The path
is a path to the directory where the wallet file is stored. The signType
is a sign type, it should be a SignType
.
static method CellFrame.Chain.Wallet.getPath() -> Tuple[str]
Gets path to the wallet directory.
static method CellFrame.Chain.Wallet.createWithSeed(name: str, path: str, sign: DAP.Crypto.SignType, seed: bytes) -> CellFrame.Chain.Wallet
Creates a new wallet. Returns the Wallet
object if successful.
static method CellFrame.Chain.Wallet.openFile(path: str) -> CellFrame.Chain.Wallet
Opens a wallet from a file with the path. Returns the Wallet
object if successful.
static method CellFrame.Chain.Wallet.open(name: str, path: str) -> CellFrame.ChainWallet
Opens a wallet with the name
and the path
to the direcrory. Returns the Wallet
object if successful.
object method CellFrame.Chain.Wallet.save() -> int
Saves wallet into the file. The wallet will be saved to the directory specified in the configuration string (see Initialization page). Returns 0
if successful.
static method CellFrame.Chain.Wallet.certToAddr(cert: DAP.Crypto.Cert, netId: CellFrame.ChainNetID) -> CellFrame.Chain.ChainAddr
Adds certificate into the wallet. The cert
should be a DAP.Crypto.Cert
object. The netId
should be a ChainNetID
object. Returns the ChainAddr
object if successful.
object method CellFrame.Chain.Wallet.getAddr(netId: CellFrame.Chain.NetID) -> CellFrame.Chain.ChainAddr
Gets a address. Returns the ChainAddr
object if successful.
object method CellFrame.Chain.Wallet.getCertsNumber() -> int
Gets a number of certifications in the wallet.
object method CellFrame.Chain.Wallet.getPKey(index: int) -> DAP.Crypto..Pkey
Gets a public key by an index. Returns the Pkey
object if a public key with such an index exists.
object method CellFrame.Chain.Wallet.getKey(index: int) -> DAP.Crypto.CryptoKey
Gets a key by an index. Returns a CryptoKey
object.
class CellFrame.Chain.Mempool
This class provides working with mempool.
staic method CellFrame.Chain.Mempool.addProc(datum: [str, CellFrame.Common.Datum] , chain: CellFrame.Chain.Chain) -> None
Processes the datum into the mempool. The datum
must be a str
object or Datum
object.
staic method CellFrame.Chain.Mempool.emissionPlace(chain: CellFrame.Chain.Chain, emission: CellFrame.Common.DatumEmission) -> str
Places an emission in the mempool. The chain
must be the Chain
object and emission
must be the DatumEmission
object. Returns a string or None
staic method CellFrame.Chain.Mempool.emissionGet(chain: CellFrame.Chain.Chain, emossionHash: str) -> CellFrame.Common.DatumEmission
Gets an emission by a hash. The chain
must be the Chain
object. Returns an instanse of the DatumEmission
object.
staic method CellFrame.Chain.Mempool.emissionExtract(chain: CellFrame.Chain.Chain, data: bytes) -> CellFrame.Common.DatumEmission
Extracts an emission datum from a chain.
staic method CellFrame.Chain.Mempool.txCreate(chain: CellFrame.Chain.Chain, keyFrom: DAP.Crypto.CryptoKey, addrFrom: CellFrame.Chain.ChainAddr, addrTo: CellFrame.Chain.ChainAddr, addrFee: CellFrame.Chain.ChainAddr, token: str, value: int, valueFee: int) -> DAP.Crypto.HashFast
Adds a transaction to mempool. The chain
is a chain to which a transaction is added, it should be a Chain
object. The keyFrom
is a key of wallet from which the transfer will be made, it should be a CryptoKey
. The addrFrom
and addrTo
are addresses of wallet from and to which the transfer will be made. The addrFee
is an address where a fee will be transferred. The addrFrom
, addrTo
and addrFee
should be a ChainAddr
object. The token
is a token ticket, for example, a "tCELL"
string. The value
is a value to be transferred. The valueFee
is a value of fee that will be withheld. Returns an instance of a ChainHashFast
object if transaction has been adde or None
if hasn't.
staic method CellFrame.Chain.Mempool.baseTxCreate(chain: CellFrame.Chain.Chain, emissionHash: HashFast, emissionChain: CellFrame.Chain.Chain, emissionValue: str, ticker: str, addrTo: CellFrame.Chain.ChainAddr, certs: List[DAP.Crypto.Cert] ) -> None
Adds a base transaction to mempool. The chain
is a chain to which we add the transaction. The emissionHash
is a emission hash. The emissionChain
is a chain which has an emission. The emissionValue
is a value in datoshi. The ticker
is a ticker The addrTo
is a address to which we translate. The list
is a list contains certifications.
staic method CellFrame.Chain.Mempool.txCreateCond(net: CellFrame.Network.Net, keyFrom: DAP.Crypto.Key, keyCond: DAP.Crypto.PKey, token: str, value: str, valuePerUnit: CellFrame.Network.ServicePriceUnitUID, srvUID: CellFrame.Network.ServiceUID, fee: str, objCond: bytes) -> DAP.Crypto.HashFast
Adds a condition transaction to mempool.
staic method CellFrame.Chain.Mempool.txCreateCondInput(net: CellFrame.Network.Net, txPrevHash: DAP.Crypto.HashFast, addrTo: CellFrame.Chain.ChainAddr, keyTxSign: DAP.Crypto.Key, receipt: CellFrame.Common.TxReceipt) -> keyFrom: DAP.Crypto.Key, keyCond: DAP.Crypto.PKey, token: str, value: str, valuePerUnit: CellFrame.Network.ServicePriceUnitUID, srvUID: CellFrame.Network.ServiceUID, fee: str, objCond: bytes) -> DAP,Crypto.HashFast
Adds a confition input transaction to mempool.
class CellFrame.Chain.Ledger
This class implements the chain ledger object.
object method CellFrame.Chain.Ledger.setLocalCellId(localCellId: CellFrame.Chain.CellID) -> int
Sets the localCellId
into the instance. Returns 0
if successful.
object method CellFrame.Chain.Ledger.nodeDatumTxCalcHash(tx: CellFrame.Common.DatumTx) -> CellFrame.ChainHashFast
Calculates the hash for the tx
transaction. Returns 0
if successful.
object method CellFrame.Chain.Ledger.txAdd(tx: CellFrame.Common.DatumTx) -> int
Adds the new tx
transaction to the cache list. Returns 1
if successful, otherwise -1
.
object method CellFrame.Chain.Ledger.tokenAdd(token: CellFrame.Common.DatumToken, tokenSize: int) -> int
Adds the new token
token to the ledger. Returns 0
if successful, otherwise error code less 0
.
object method CellFrame.Chain.Ledger.tokenEmissionAdd(tokenEmission: CellFrame.Common.DatumTokenEmission, tokenEmissionSize: int) -> int
Adds the new tokenEmission
token to the ledger. Returns 0
if successful, otherwise error code less 0
.
object method CellFrame.Chain.Ledger.tokenEmissionFind(tokenTicker: str, hash: DAP.Crypto.HashFast) -> CellFrame.Common.DatumTokenEmission
Finds the token emission by the tokenTicker
and the hash
. Returns the CellFrame.Common.DatumTokenEmission
object if it was found.
Not implementations yet.
object method CellFrame.Chain.Ledger.addrGetTokenTickerAll(address: CellFrame.Chain.ChainAddr, tickers: List[str], sizeTickers: int) -> int
Produces all tokens received by address
. Returns 0
if successful.
object method CellFrame.Chain.Ledger.addrGetTokenTickerAllFast(address: CellFrame.Chain.ChainAddr) -> List[str]
Gets all tokens by the address
. Returns the list consisting of tokens.
object method CellFrame.Chain.Ledger.txCacheCheck(datumTx: CellFrame.Common.DatumTx, boundItems: List[List[bytes]], listTxOut: List[List[bytes]]) -> int
Checks a new transaction before adding to the cache. Returns 1
if successful, otherwise -1
.
Not implementations yet.
object method CellFrame.Chain.Ledger.txRemove(hash: DAP.Crypto.HashFast) -> int
Removes a transaction by the hash
from the log with the corresponding cache. Returns 1
if successful, otherwise error code less 0
.
object method CellFrame.Chain.Ledger.purge(preserveDb: bool) -> None
Deletes all transactions from the cache. Returns nothing.
object method CellFrame.Chain.Ledger.count() -> int
Counts the number of transactions in the cache. Returns the number.
object method CellFrame.Chain.Ledger.countFromTo(tsFrom: int, tsTo: int = None) -> int
Counts the number of transactions starting from time tsFrom
to tsTo
in the cache. Returns the number.
object method CellFrame.Chain.Ledger.txHashIsUsedOutItem(hash: DAP.Crypto.HashFast, idx_out: int) -> bool
Checks if a given hash
is being used 'out'. Returns True
if it is, otherwise False
.
object method CellFrame.Chain.Ledger.calcBalance(address: CellFrame.Chain.ChainAddr, token_ticker: str) -> Tuple[str, int]
Calculates the balance of address
. Returns a tuple consisting of a balance in the form of a string and a value.
object method CellFrame.Chain.Ledger.calcBalanceFull(address: CellFrame.Chain.ChainAddr, token_ticker: str) -> int
Calculates the full balance of address
. Returns a tuple consisting of a balance in the form of a string and a number.
object method CellFrame.Chain.Ledger.txFindByHash(hash: DAP.Crypto.HashFast) -> Optional[CellFrame.Common.DatumTx]
Gets a transaction by hash
. Returns the DatumTx
object if it was found, otherwise None
.
object method CellFrame.Chain.Ledger.txFindByAddr(token: str, address: CellFrame.ChainAddr, firstHash: CellFrame.HashFast) -> CellFrame.ChainDatumTx
Gets a transaction by the address
in out item, starting with firstHash
. Returns the ChainDatumTx
object.
object method CellFrame.Chain.Ledger.txFindByPkey(pKey: str, pKeySize: int, address: CellFrame.ChainAddr, firstHash: CellFrame.HashFast) -> CellFrame.Common.DatumTx
Gets the transaction by the pKey
public key that signed the transaction, starting with firstHash
. Returns the ChainDatumTx
object.
object method CellFrame.Chain.Ledger.txCacheFindOutCond(firstHash: DAP.Crypto.HashFast) -> CellFrame.Common.DatumTx
Gets the transaction with the out_cond item, starting with firstHash
. Returns the ChainDatumTx
object.
object method CellFrame.Chain.Ledger.txCacheFindOutCond(address: CellFrame.Chain.ChainAddr) -> Tuple[int, CellFrame.Common.TxOutCond]
Gets the value from all transactions with out_cond item. Returns the tuple consisting of the value and the TxOutCond
object.