-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui: new accounts #125
ui: new accounts #125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -792,6 +792,7 @@ class Account: | |
|
||
def __init__( | ||
self, | ||
idx, | ||
pubKeyEncrypted, | ||
privKeyEncrypted, | ||
name, | ||
|
@@ -802,6 +803,7 @@ def __init__( | |
): | ||
""" | ||
Args: | ||
idx (int): The BIP-0044 account index. | ||
pubKeyEncrypted (ByteArray): The encrypted public key bytes. | ||
privKeyEncrypted (ByteArray): The encrypted private key bytes. | ||
name (str): Name for the account. | ||
|
@@ -815,6 +817,7 @@ def __init__( | |
signals (Signals): A signaller. Only used if db and blockchain are | ||
specified. | ||
""" | ||
self.idx = idx | ||
self.pubKeyEncrypted = pubKeyEncrypted | ||
self.privKeyEncrypted = privKeyEncrypted | ||
self.name = name | ||
|
@@ -867,6 +870,7 @@ def blob(acct): | |
"""Satisfies the encode.Blobber API""" | ||
return ( | ||
BuildyBytes(0) | ||
.addData(encode.intToBytes(acct.idx)) | ||
.addData(acct.pubKeyEncrypted) | ||
.addData(acct.privKeyEncrypted) | ||
.addData(acct.name.encode("utf-8")) | ||
|
@@ -881,18 +885,19 @@ def blob(acct): | |
def unblob(b): | ||
"""Satisfies the encode.Blobber API""" | ||
ver, d = encode.decodeBlob(b) | ||
unblob_check("Account", ver, len(d), {0: 7}) | ||
unblob_check("Account", ver, len(d), {0: 8}) | ||
|
||
iFunc = encode.intFromBytes | ||
|
||
pubEnc = ByteArray(d[0]) | ||
privEnc = ByteArray(d[1]) | ||
name = d[2].decode("utf-8") | ||
netID = d[3].decode("utf-8") | ||
acct = Account(pubEnc, privEnc, name, netID) | ||
acct.cursorExt = iFunc(d[4], signed=True) | ||
acct.cursorInt = iFunc(d[5]) | ||
acct.gapLimit = iFunc(d[6]) | ||
idx = iFunc(d[0]) | ||
pubEnc = ByteArray(d[1]) | ||
privEnc = ByteArray(d[2]) | ||
name = d[3].decode("utf-8") | ||
netID = d[4].decode("utf-8") | ||
acct = Account(idx, pubEnc, privEnc, name, netID) | ||
acct.cursorExt = iFunc(d[5], signed=True) | ||
acct.cursorInt = iFunc(d[6]) | ||
acct.gapLimit = iFunc(d[7]) | ||
return acct | ||
|
||
def serialize(self): | ||
|
@@ -1432,7 +1437,7 @@ def nextExternalAddress(self): | |
self.nextBranchAddress(self.extPub, extAddrs, self.addrExtDB) | ||
addr = extAddrs[idx] | ||
if self.blockchain: | ||
self.blockchain.subscribeAddresses(addr) | ||
self.blockchain.subscribeAddresses(addr, self.addressSignal) | ||
return addr | ||
|
||
def nextInternalAddress(self): | ||
|
@@ -1955,14 +1960,13 @@ def sync(self): | |
signals.balance(self.calcBalance()) | ||
self.generateGapAddresses() | ||
|
||
# If there is a chosen stake pool, sync the purchaseInfo. | ||
# TODO: Save purchase info | ||
# If there is a chosen stake pool, authorize the pool. | ||
stakePool = self.stakePool() | ||
if stakePool: | ||
try: | ||
stakePool.getPurchaseInfo() | ||
stakePool.authorize(self.votingAddress().string()) | ||
Comment on lines
-1963
to
+1967
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JoeGruffins I didn't see any problem calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. |
||
except Exception as e: | ||
log.error("error getting VSP purchase info: %s" % e) | ||
log.error("error authorizing VSP: %s" % e) | ||
|
||
# First, look at addresses that have been generated but not seen. Run in | ||
# loop until the gap limit is reached. | ||
|
@@ -1975,35 +1979,39 @@ def sync(self): | |
requestedTxs += 1 | ||
self.addTxid(addr, txid) | ||
addrs = self.generateGapAddresses() | ||
log.debug("%d address transactions sets fetched" % requestedTxs) | ||
log.debug( | ||
f"{requestedTxs} address transactions fetched for account {self.name}" | ||
) | ||
|
||
# start with a search for all known addresses | ||
addresses = self.allAddresses() | ||
|
||
# Until the server stops returning UTXOs, keep requesting more addresses | ||
# to check. | ||
utxoCount = 0 | ||
while True: | ||
# Update the account with known UTXOs. | ||
blockchainUTXOs = blockchain.UTXOs(addresses) | ||
if not blockchainUTXOs: | ||
break | ||
utxoCount += len(blockchainUTXOs) | ||
self.resolveUTXOs(blockchainUTXOs) | ||
addresses = self.generateGapAddresses() | ||
if not addresses: | ||
break | ||
log.debug(f"{utxoCount} utxos for account {self.name}") | ||
|
||
# update the staking info and authorize the stake pool. | ||
# Update the staking info. | ||
self.updateStakeStats() | ||
pool = self.stakePool() | ||
if pool: | ||
pool.authorize(self.votingAddress().string()) | ||
|
||
# Subscribe to block and address updates. | ||
blockchain.addressReceiver = self.addressSignal | ||
blockchain.subscribeBlocks(self.blockSignal) | ||
watchAddresses = self.watchAddrs() | ||
if watchAddresses: | ||
blockchain.subscribeAddresses(watchAddresses) | ||
blockchain.subscribeAddresses(watchAddresses, self.addressSignal) | ||
log.debug( | ||
f"subscribed to {len(watchAddresses)} addresses for account {self.name}" | ||
) | ||
# Signal the new balance. | ||
signals.balance(self.calcBalance()) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,10 +409,6 @@ def __init__(self, db, netParams, datapath, skipConnect=False): | |
db = database.KeyValueDatabase(db) | ||
self.db = db | ||
self.netParams = netParams | ||
# The blockReceiver and addressReceiver will be set when the respective | ||
# subscribe* method is called. | ||
self.blockReceiver = None | ||
self.addressReceiver = None | ||
self.datapath = datapath | ||
self.dcrdata = None | ||
self.txDB = db.child("tx", blobber=msgtx.MsgTx) | ||
|
@@ -421,6 +417,8 @@ def __init__(self, db, netParams, datapath, skipConnect=False): | |
self.txBlockMap = db.child("blocklink") | ||
self.tipHeight = None | ||
self.subsidyCache = calc.SubsidyCache(netParams) | ||
self.addrSubscribers = {} | ||
self.blockSubscribers = [] | ||
Comment on lines
+420
to
+421
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different receivers for different addresses allows the |
||
if not skipConnect: | ||
self.connect() | ||
|
||
|
@@ -448,7 +446,7 @@ def subscribeBlocks(self, receiver): | |
receiver (func(object)): A function or method that accepts the block | ||
notifications. | ||
""" | ||
self.blockReceiver = receiver | ||
self.blockSubscribers.append(receiver) | ||
self.dcrdata.subscribeBlocks() | ||
|
||
def getAgendasInfo(self): | ||
|
@@ -460,7 +458,7 @@ def getAgendasInfo(self): | |
""" | ||
return agenda.AgendasInfo.parse(self.dcrdata.stake.vote.info()) | ||
|
||
def subscribeAddresses(self, addrs, receiver=None): | ||
def subscribeAddresses(self, addrs, receiver): | ||
""" | ||
Subscribe to notifications for the provided addresses. | ||
|
||
|
@@ -470,10 +468,8 @@ def subscribeAddresses(self, addrs, receiver=None): | |
notifications. | ||
""" | ||
log.debug("subscribing to addresses %s" % repr(addrs)) | ||
if receiver: | ||
self.addressReceiver = receiver | ||
elif self.addressReceiver is None: | ||
raise DecredError("must set receiver to subscribe to addresses") | ||
for addr in addrs: | ||
self.addrSubscribers[addr] = receiver | ||
self.dcrdata.subscribeAddresses(addrs) | ||
|
||
def processNewUTXO(self, utxo): | ||
|
@@ -840,11 +836,17 @@ def pubsubSignal(self, sig): | |
try: | ||
if sigType == "address": | ||
msg = sig["message"] | ||
addr = msg["address"] | ||
log.debug("signal received for %s" % msg["address"]) | ||
self.addressReceiver(msg["address"], msg["transaction"]) | ||
receiver = self.addrSubscribers.get(addr) | ||
if not receiver: | ||
log.error("no receiver registered for address %s", addr) | ||
return | ||
receiver(addr, msg["transaction"]) | ||
elif sigType == "newblock": | ||
self.tipHeight = sig["message"]["block"]["height"] | ||
self.blockReceiver(sig) | ||
for receiver in self.blockSubscribers: | ||
receiver(sig) | ||
elif sigType == "subscribeResp": | ||
# should check for error. | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified the encoding without updating the version. Sync from mnemonic seed. I am planning on stopping doing this soon, maybe after we resolve #102.