def blob(vsp): """Satisfies the encode.Blobber API""" pi = PurchaseInfo.blob(vsp.purchaseInfo) if vsp.purchaseInfo else None return (encode.BuildyBytes(0).addData(vsp.url.encode("utf-8")).addData( vsp.apiKey.encode("utf-8")).addData( vsp.netParams.Name.encode("utf-8")).addData( encode.filterNone(pi)).b)
def blob(pi): """Satisfies the encode.Blobber API""" return (encode.BuildyBytes(0).addData( pi.poolAddress.encode("utf-8")).addData( encode.floatToBytes(pi.poolFees)).addData(pi.script).addData( pi.ticketAddress.encode("utf-8")).addData( pi.voteBits).addData(pi.voteBitsVersion).addData( pi.unixTimestamp).b)
def baseParams(self): """ Serializes all the parameters except the authentication code. Returns: BuildyBytes: The serialized parameters. """ return (encode.BuildyBytes(0).addData( self.kdfFunc.encode("utf-8")).addData( self.hashName.encode("utf-8")).addData(self.salt).addData( self.iterations))
def test_account_manager(monkeypatch, prepareLogger): # Set up globals for test. monkeypatch.setattr(account, "DefaultGapLimit", 2) cryptoKey = rando.newKey() db = database.KeyValueDatabase(":memory:").child("tmp") # 42 = Decred acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, 42, nets.mainnet, db) acct = acctMgr.openAccount(0, cryptoKey) tempAcct = acctMgr.addAccount(cryptoKey, "temp") assert acctMgr.account(1) == tempAcct assert acctMgr.listAccounts() == [acct, tempAcct] acctMgr.setNode("node") assert acctMgr.node == "node" assert tempAcct.node == "node" acctMgr.accounts[3] = tempAcct del acctMgr.accounts[1] with pytest.raises(DecredError): acctMgr.listAccounts() del acctMgr.accounts[3] with pytest.raises(DecredError): accounts.AccountManager.unblob(encode.BuildyBytes(0)) zeroth = acct.currentAddress() b = acctMgr.serialize() reAM = accounts.AccountManager.unblob(b.b) assert acctMgr.coinType == reAM.coinType assert acctMgr.netName == reAM.netName assert acctMgr.netName == reAM.netName reAM.load(db, None) reAcct = reAM.openAccount(0, cryptoKey) reZeroth = reAcct.currentAddress() assert zeroth == reZeroth acctMgr.saveAccount(0) db = acctMgr.dbForAcctIdx(0) assert db.name == "tmp$accts$0"