Skip to content

Commit

Permalink
vsp and ticket screens for gui. pay-to-stake-pubkey-hash script signing
Browse files Browse the repository at this point in the history
Updated interface to support ticket purchases via VSP. No solo voting
and still needs revocation support, but signing stake-P2PKH outputs
of all types is now supported.
  • Loading branch information
buck54321 committed Sep 17, 2019
1 parent 77eb9a1 commit 01a68f2
Show file tree
Hide file tree
Showing 16 changed files with 1,296 additions and 366 deletions.
41 changes: 34 additions & 7 deletions accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
The tinycrypto package relies heavily on the lower-level crypto modules.
"""
import unittest
import hashlib
from tinydecred.util import tinyjson, helpers
from tinydecred import api
from tinydecred.pydecred import nets, constants as DCR
Expand Down Expand Up @@ -223,8 +222,9 @@ def __tojson__(self):
"balance": self.balance,
}
@staticmethod
def __fromjson__(obj):
acct = Account(
def __fromjson__(obj, cls=None):
cls = cls if cls else Account
acct = cls(
obj["pubKeyEncrypted"],
obj["privKeyEncrypted"],
obj["name"],
Expand Down Expand Up @@ -328,6 +328,30 @@ def spendUTXO(self, utxo):
return self.utxos.pop(utxo.key(), None)
def resolveUTXOs(self, blockchainUTXOs):
self.utxos = {u.key(): u for u in blockchainUTXOs}
def getUTXOs(self, requested, approve=None):
"""
Find confirmed and mature UTXOs, smallest first, that sum to the
requested amount, in atoms.
Args:
requested int: Required amount. Atoms.
filter func(UTXO) -> bool: Optional UTXO filtering function.
Returns:
list(UTXO): A list of UTXOs.
bool: Success. True if the UTXO sum is >= the requested amount.
"""
matches = []
collected = 0
pairs = [(u.satoshis, u) for u in self.utxoscan()]
for v, utxo in sorted(pairs, key=lambda p: p[0]):
if approve and not approve(utxo):
continue
matches.append(utxo)
collected += v
if collected >= requested:
break
return matches, collected >= requested
def spendTxidVout(self, txid, vout):
"""
Spend the UTXO.
Expand Down Expand Up @@ -474,7 +498,7 @@ def addressesOfInterest(self):
ext = self.externalAddresses
for i in range(max(self.cursor - 10, 0), self.cursor+1):
a.add(ext[i])
return a
return list(a)
def paymentAddress(self):
"""
Get the external address at the cursor. The cursor is not moved.
Expand Down Expand Up @@ -677,7 +701,8 @@ def acctPublicKey(self, acct, net, pw):

tinyjson.register(AccountManager)

def createNewAccountManager(seed, pubPassphrase, privPassphrase, chainParams):

def createNewAccountManager(seed, pubPassphrase, privPassphrase, chainParams, constructor=None):
"""
Create a new account manager and a set of BIP0044 keys for creating
accounts. The zeroth account is created for the provided network parameters.
Expand All @@ -690,7 +715,9 @@ def createNewAccountManager(seed, pubPassphrase, privPassphrase, chainParams):
privPassphrase (byte-like): A user-supplied password to protect the
private the account private keys.
chainParams (obj): Network parameters.
constructor (class): An account class.
"""
constructor = constructor if constructor else Account

# Ensure the private passphrase is not empty.
if len(privPassphrase) == 0:
Expand Down Expand Up @@ -774,12 +801,12 @@ def createNewAccountManager(seed, pubPassphrase, privPassphrase, chainParams):

# Save the information for the default account to the database. This
# account is derived from the legacy coin type.
baseAccount = Account(acctPubLegacyEnc, acctPrivLegacyEnc,
baseAccount = constructor(acctPubLegacyEnc, acctPrivLegacyEnc,
DEFAULT_ACCOUNT_NAME, CoinSymbols.decred, chainParams.Name)

# Save the account row for the 0th account derived from the coin type
# 42 key.
zerothAccount = Account(acctPubSLIP0044Enc, acctPrivSLIP0044Enc,
zerothAccount = constructor(acctPubSLIP0044Enc, acctPrivSLIP0044Enc,
DEFAULT_ACCOUNT_NAME, CoinSymbols.decred, chainParams.Name)
# Open the account
zerothAccount.open(cryptoKeyPriv)
Expand Down
9 changes: 8 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from tinydecred.pydecred import constants as DCR
from tinydecred.pydecred.dcrdata import DcrdataBlockchain
from tinydecred.wallet import Wallet
from tinydecred.crypto import crypto
from tinydecred.ui import screens, ui, qutilities as Q

# The directory of the tinydecred package.
Expand Down Expand Up @@ -125,6 +124,8 @@ def __init__(self, qApp):

self.sendScreen = screens.SendScreen(self)

self.confirmScreen = screens.ConfirmScreen(self)

self.sysTray.show()
self.appWindow.show()

Expand Down Expand Up @@ -353,6 +354,11 @@ def step2(pw, a, k):
self.emitSignal(ui.DONE_SIGNAL)
return False
self.getPassword(step1, cb, a, k)
def confirm(self, msg, cb):
"""
Call the callback function only if the user confirms the prompt.
"""
self.appWindow.stack(self.confirmScreen.withPurpose(msg, cb))
def tryInitSync(self):
"""
If conditions are right, start syncing the wallet.
Expand Down Expand Up @@ -395,6 +401,7 @@ def setDCR(self, res):
if not res:
self.appWindow.showError("No dcrdata connection available.")
return
self.emitSignal(ui.BLOCKCHAIN_CONNECTED)
self.tryInitSync()
def getButton(self, size, text, tracked=True):
"""
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def save(self):
"""
Save the file.
"""
tinyjson.save(CONFIG_PATH, self.file)
tinyjson.save(CONFIG_PATH, self.file, indent=4, sort_keys=True)

# The configuration is only loaded once. Successive calls to the modular `load`
# function will return the same instance.
Expand Down
25 changes: 0 additions & 25 deletions crypto/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,31 +417,6 @@ def __init__(self, privVer, pubVer, key, pubKey, chainCode, parentFP, depth, chi
self.depth = depth
self.childNum = childNum
self.isPrivate = isPrivate
# def __tojson__(self):
# return {
# "privVer": self.privVer,
# "pubVer": self.pubVer,
# "key": self.key,
# "pubKey": self.pubKey,
# "chainCode": self.chainCode,
# "parentFP": self.parentFP,
# "depth": self.depth,
# "childNum": self.childNum,
# "isPrivate": self.isPrivate,
# }
# @staticmethod
# def __fromjson__(obj):
# return ExtendedKey(
# privVer = obj["privVer"],
# pubVer = obj["pubVer"],
# key = obj["key"],
# pubKey = obj["pubKey"],
# chainCode = obj["chainCode"],
# parentFP = obj["parentFP"],
# depth = obj["depth"],
# childNum = obj["childNum"],
# isPrivate = obj["isPrivate"],
# )
def deriveCoinTypeKey(self, coinType):
"""
First two hardened child derivations in accordance with BIP0044.
Expand Down
Loading

0 comments on commit 01a68f2

Please sign in to comment.