def __setattr__(self, attr, value): if attr in ["delegate", "registered", "forger", "K1", "K2", "account"]: raise ReadOnlyAttributes( "%s can not be set through Wallet interface" % attr) elif attr == "secret": keys = core.getKeys(value) public_key = binascii.hexlify(keys.public) object.__setattr__(self, "address", core.getAddress(keys)) object.__setattr__( self, "publicKey", public_key.decode() if isinstance(public_key, bytes) else public_key) object.__setattr__(self, "K1", keys) self.update() @setInterval(20) def _check(obj): obj.update() self._stop_check_daemon = _check(self) elif attr == "secondSecret": if self.account.get('secondSignature', False): keys = core.getKeys(value) keys.pop("wif") object.__setattr__(self, "K2", keys) else: raise SecondSignatureError( "Second signature is registered to this wallet") else: object.__setattr__(self, attr, value)
def _generate_tx(self, **kw): """ Generate a transaction with wallet key(s) """ tx = core.Transaction(**kw) object.__setattr__(tx, "key_one", self.K1) object.__setattr__(tx, "address", core.getAddress(self.K1)) if hasattr(self, "K2"): object.__setattr__(tx, "key_two", self.K2) return tx
def open(filename): in_ = io.open(filename, "r") K1, K2 = json.load(in_) in_.close() obj = Wallet() K1 = core.unserializeKeys(K1) public_key = binascii.hexlify(K1.public) object.__setattr__(obj, "address", core.getAddress(K1)) object.__setattr__( obj, "publicKey", public_key.decode() if isinstance(public_key, bytes) else public_key) object.__setattr__(obj, "K1", K1) obj.update() if K2: object.__setattr__(obj, "K2", core.unserializeKeys(K2)) @setInterval(20) def _check(o): obj.update() obj._stop_check_daemon = _check(obj) return obj