Skip to content
Snippets Groups Projects
Commit 4008070d authored by Fabian Schuh's avatar Fabian Schuh
Browse files

[memo] improve interface of bitshares.memo

parent 03707966
No related branches found
No related tags found
No related merge requests found
......@@ -177,16 +177,6 @@ class BitShares(object):
def prefix(self):
return self.rpc.chain_params["prefix"]
def newWallet(self, pwd):
""" Create a new wallet. This method is basically only calls
:func:`bitshares.wallet.create`.
:param str pwd: Password to use for the new wallet
:raises bitshares.exceptions.WalletExists: if there is already a
wallet created
"""
self.wallet.create(pwd)
def set_default_account(self, account):
""" Set the default account to be used
"""
......@@ -300,6 +290,24 @@ class BitShares(object):
"""
return self.rpc.get_dynamic_global_properties()
# -------------------------------------------------------------------------
# Wallet stuff
# -------------------------------------------------------------------------
def newWallet(self, pwd):
""" Create a new wallet. This method is basically only calls
:func:`bitshares.wallet.create`.
:param str pwd: Password to use for the new wallet
:raises bitshares.exceptions.WalletExists: if there is already a
wallet created
"""
return self.wallet.create(pwd)
def unlock(self, *args, **kwargs):
""" Unlock the internal wallet
"""
return self.wallet.unlock(*args, **kwargs)
# -------------------------------------------------------------------------
# Transaction Buffers
# -------------------------------------------------------------------------
......
......@@ -11,6 +11,12 @@ class WalletLocked(Exception):
pass
class RPCConnectionRequired(Exception):
""" An RPC connection is required
"""
pass
class AccountExistsException(Exception):
""" The requested account already exists
"""
......
......@@ -56,6 +56,12 @@ class Memo(object):
if from_account:
self.from_account = Account(from_account, bitshares_instance=self.bitshares)
def unlock_wallet(self, *args, **kwargs):
""" Unlock the library internal wallet
"""
self.bitshares.wallet.unlock(*args, **kwargs)
return self
def encrypt(self, memo):
""" Encrypt a memo
......
......@@ -9,7 +9,8 @@ from .exceptions import (
WalletExists,
WalletLocked,
WrongMasterPasswordException,
NoWalletException
NoWalletException,
RPCConnectionRequired
)
log = logging.getLogger(__name__)
......@@ -54,12 +55,13 @@ class Wallet():
keys = {} # struct with pubkey as key and wif as value
keyMap = {} # type:wif pairs to force certain keys
def __init__(self, rpc, *args, **kwargs):
def __init__(self, rpc=None, *args, **kwargs):
from .storage import configStorage
self.configStorage = configStorage
# RPC
Wallet.rpc = rpc
# RPC static variable
if rpc:
Wallet.rpc = rpc
# Prefix?
if Wallet.rpc:
......
......@@ -76,14 +76,21 @@ Decoding of a received memo
from bitshares.block import Block
from bitshares.memo import Memo
block = Block(23755086)
transaction = block["transactions"][3]
op = transaction["operations"][0]
op_id = op[0]
op_data = op[1]
# Obtain a transfer from the blockchain
block = Block(23755086) # block
transaction = block["transactions"][3] # transactions
op = transaction["operations"][0] # operation
op_id = op[0] # operation type
op_data = op[1] # operation payload
# Instantiate Memo for decoding
memo = Memo()
memo.bitshares.wallet.unlock(getpass())
# Unlock wallet
memo.unlock_wallet(getpass())
# Decode memo
# Raises exception if required keys not available in the wallet
print(memo.decrypt(op_data["memo"]))
API
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment