def __init__(self, public, is_mainnet): self._path = 'main123' if is_mainnet else 'test123' self.AddressVersion = 23 self._lock = RLock() self._indexedDB = Blockchain.Default() self.BuildDatabase() self._keys = {} self._contracts = self.LoadContracts() for key, contract in self._contracts.items(): print('contract ScriptHash', contract.ScriptHash) print('initializing', flush=True) kp = OnlyPublicKeyPair(public) self._keys[kp.PublicKeyHash.ToBytes()] = kp contract = WalletContract.CreateSignatureContract(kp.PublicKey) if contract.ScriptHash.ToBytes() not in self._contracts.keys(): self._contracts[contract.ScriptHash.ToBytes()] = contract sh = bytes(contract.ScriptHash.ToArray()) address, created = Address.get_or_create(ScriptHash=sh) address.IsWatchOnly = False address.save() db_contract = Contract.create(RawData=contract.ToArray(), ScriptHash=contract.ScriptHash.ToBytes(), PublicKeyHash=contract.PublicKeyHash.ToBytes(), Address=address, Account=None ) self.LoadNamedAddresses() self._watch_only = self.LoadWatchOnly() self._tokens = self.LoadNEP5Tokens() self._coins = self.LoadCoins() # self.initialize_holds() self._holds = VINHold.filter(IsComplete=False) # Handle EventHub events for SmartContract decorators @events.on(SmartContractEvent.RUNTIME_NOTIFY) def call_on_event(sc_event): # Make sure this event is for this specific smart contract self.on_notify_sc_event(sc_event) try: self._current_height = int(self.LoadStoredData('Height')) except: print('setting height to 0') self._current_height = 0 self.SaveStoredData('Height', self._current_height)
def process_hold_created_event(self, payload): if len(payload) == 4: vin = payload[0] from_addr = UInt160(data=payload[1]) to_addr = UInt160(data=payload[2]) amount = int.from_bytes(payload[3], 'little') v_index = int.from_bytes(vin[32:], 'little') v_txid = UInt256(data=vin[0:32]) if to_addr.ToBytes() in self._contracts.keys() and from_addr in self._watch_only: hold, created = VINHold.get_or_create( Index=v_index, Hash=v_txid.ToBytes(), FromAddress=from_addr.ToBytes(), ToAddress=to_addr.ToBytes(), Amount=amount, IsComplete=False ) if created: self.LoadHolds()
def LoadCompletedHolds(self): return VINHold.filter(IsComplete=True)
def LoadHolds(self): self._holds = VINHold.filter(IsComplete=False) return self._holds