Esempio n. 1
0
    @staticmethod
    def __fromjson__(obj):
        p = KDFParams(
            salt=obj["salt"],
            digest=obj["digest"],
        )
        p.iterations = obj["iterations"]
        p.hashName = obj["hashName"]
        p.kdfFunc = obj["kdfFunc"]
        return p

    def __repr__(self):
        return repr(self.__tojson__())


tinyjson.register(KDFParams)


class ScryptParams(object):
    """
    A set of scrypt parameters. Can be stored and retreived in plain text to
    regenerate encryption keys.
    """
    def __init__(self, salt, digest, n, r, p):
        """
        Args:
            salt (ByteArray): A randomized salt.
            digest: Key hash used as a checksum.
            n (int): Scrypt iteration count, N.
            r (int): Scrypt memory factor, r.
            p (int): Scrypt parallelization factor, p.
Esempio n. 2
0
        Args:
            value int: The amount to send, in atoms.
            address str: The base-58 encoded pubkey hash.

        Returns: 
            MsgTx: The newly created transaction on success, `False` on failure.
        """
        acct = self.openAccount
        keysource = KeySource(
            priv=self.getKey,
            change=acct.getChangeAddress,
        )
        tx, spentUTXOs, newUTXOs = self.blockchain.sendToAddress(
            value, address, keysource, self.getUTXOs, feeRate)
        acct.addMempoolTx(tx)
        acct.spendUTXOs(spentUTXOs)
        for utxo in newUTXOs:
            acct.addUTXO(utxo)
        self.signals.balance(acct.calcBalance(self.blockchain.tip["height"]))
        self.save()
        return tx


tinyjson.register(Wallet)


class TestWallet(unittest.TestCase):
    def test_tx_to_outputs(self):
        pass
Esempio n. 3
0
    def littleEndian(self):
        return ByteArray(reversed(self.b))

    def copy(self):
        return ByteArray(self.b)

    def pop(self, n):
        """ Remove n bytes from the beginning of the ByteArray, returning the bytes."""
        b = self[:n]
        self.b = self.b[n:]
        return b


# register the ByteArray class with the json encoder/decoder.
tinyjson.register(ByteArray)


class TestByteArray(unittest.TestCase):
    def test_operators(self):
        makeA = lambda: ByteArray(bytearray([0, 0, 255]))
        makeB = lambda: ByteArray(bytearray([0, 255, 0]))
        makeC = lambda: ByteArray(bytearray([255, 0, 0]))
        zero = ByteArray(bytearray([0, 0, 0]))

        a = makeA()
        b = makeB()
        a |= b
        self.assertEqual(a, bytearray([0, 255, 255]))

        c = makeC()
Esempio n. 4
0
    def __tojson__(self):
        return {
            "total": self.total,
            "available": self.available,
        }

    @staticmethod
    def __fromjson__(obj):
        return Balance(total=obj["total"], available=obj["available"])

    def __repr__(self):
        return ("Balance(total=%.8f, available=%.8f)" %
                (self.total * 1e-8, self.available * 1e-8))


tinyjson.register(Balance)

UTXO = api.UTXO


class Account(object):
    """
    A BIP0044 account. Keys are stored as encrypted strings. The account is 
    JSON-serializable with the tinyjson module. Unencoded keys will not be 
    serialized. 
    """
    def __init__(self, pubKeyEncrypted, privKeyEncrypted, name, coinID, netID):
        """
        Args:
            pubKeyEncrypted (str): The encrypted public key bytes.
            privKeyEncrypted (str): The encrypted private key bytes.
Esempio n. 5
0
        self.ts = block.timestamp

    def isSpendable(self, tipHeight):
        if self.maturity:
            return self.maturity <= tipHeight
        return True

    def key(self):
        return UTXO.makeKey(self.txid, self.vout)

    @staticmethod
    def makeKey(txid, vout):
        return txid + "#" + str(vout)


tinyjson.register(UTXO)


def makeOutputs(
    pairs, chain
):  #pairs map[string]dcrutil.Amount, chainParams *chaincfg.Params) ([]*wire.TxOut, error) {
    """
    makeOutputs creates a slice of transaction outputs from a pair of address
    strings to amounts.  This is used to create the outputs to include in newly
    created transactions from a JSON object describing the output destinations
    and amounts.

    Args:
        pairs (tuple(str, int)): Base58-encoded address strings and atoms to
            send to the address.
        chain obj: Network parameters.