More details about the design as requested. Anyone is free to submit feedback and offer suggestions.
BlockChainInterface for implementation of PrimaryBlockChain and AuxiluryBlockChain objects. This is already complete (source will be provided), these methods should be implemented when extending this object.
def Submit(self, solution):
def Update(self):
def GetData(self):
def Set_OnSubmit(self, _call_back):
def Set_OnUpdate(self, _call_back):
PrimaryBlockChainImplements a BlockChain Interface. It is used by the Engineer object as a means of data retrieval and block submission for the network where PoW is being performed.
Public MethodsSubmitThe engineer will 'submit' a solution (aka: share/block) to the PrimaryBlockChain object using this method. The solution has already been validated and finalized into a submittable block by the Engineer.
This should be a deferred method where the program does not block execution while the PrimaryBlockChain processes the submission. When the block is accepted/rejected the method specified by 'Set_OnSubmit' should be called with the resulting information.
If the block is accepted, the PrimaryBlockChain object should perform an update request.
UpdateThe engineer may call this method upon program initialization for initial construction of a block template. It's also possible that this method may be called by the engineer via an external process (such as a new block notification mechanism)
This should be a deferred where the program does not block execution while the PrimaryBlockChain waits for data. Once data is received the method specified by 'Set_OnUpdate' should be called with the resulting information.
GetDataAllows the on demand retrieval of the currently loaded data (cached) from when the last update was run. This method may be called by the Engineer when checking for block candidates and may be called by the Poller when comparing cached data with live data.
Set_OnSubmitThis method allows the Engineer to set a callback method to be executed upon a successful or failed block submission.
Set_OnUpdateThis method allows the Engineer to set a callback method to be executed any time new data is received from the upstream network.
Call BacksThese are the callbacks as set by the 'Set_OnXXXX' public methods.
<OnSubmit>Return an indication of a successful or failed block submission with block hash and height as additional information. If submission failed, then no additional data is provided.
<OnUpdate>Returns a data package containing all the information necessary to construct a block template. Basically it should be whatever the 'getblocktemplate' RPC call returns.
Object InitializationThe constructor should require that an RPC object be provided during initialization.
UpdaterInternal object responsible for retrieving data via the 'getblocktemplate' RPC call. Used by BlockChain implementing objects and Poller.
Public MethodsUpdateThis is what begins the actual 'update' process. An optional parameter is passed indicating if this should be a 'forced' update (false by default).
Object InitializationThe constructor should require that an RPC object be provided during initialization.
PollerInternal object responsible for manually comparing the 'prevhash' to detect a new block and/or update the Merkle tree.
Public MethodsSetIntervalSelf Explanatory, allows the ability to specify a polling interval.
Object InitializationThe constructor should require that an RPC object be provided during initialization.
RPCThe Updater, Poller, and PrimaryBlockChain objects utilize this as a means of communicating with the upstream network. This is already implemented, the following methods are exposed:
def call(self, method, params):
def submitblock(self, block_hex, hash_hex, raw_hex, method, num_retries):
def getinfo(self):
def getblocktemplate(self, num_retries):
def prevhash(self):
def validateaddress(self, address):
def getdifficulty(self):
def blockexists(self, hash_hex):
def set_getblocktemplate_pollformat(self, format):
def set_has_submitblock(self, enabled):