Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Merge 9a2189f into 467eceb
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Oct 6, 2018
2 parents 467eceb + 9a2189f commit bd357f8
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 502 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project are documented in this file.
- Add ``sendmany`` and ``sendfrom`` RPC methods & tests and integrate with ``sendtoaddress``
- Updated all the dependencies
- Add ``Neo.Transaction.GetWitnesses``, ``Neo.Witness.GetInvocationScript``, ``Neo.Witness.GetVerificationScript``
- Removes all ``hold`` and ``withdraw`` related functionality from wallet and prompt
- Fix 'script_hash' output in ``ToJson`` in AccountState, Adds an 'address' key, Adds a test for ``ToJson`` in AccountState, Replaces the variable ``script_hash`` in ``GetAccountState`` in LevelDBBlockchain with ``address``, Adds a test for ``GetAccountState`` in LevelDBBlockchain
- Add documentation support for Python 3.7

Expand Down
60 changes: 3 additions & 57 deletions neo/Implementations/Wallets/peewee/UserWallet.py
Expand Up @@ -34,55 +34,16 @@ class UserWallet(Wallet):

_aliases = None

_holds = None

_db = None

def __init__(self, path, passwordKey, create):

super(UserWallet, self).__init__(path, passwordKey=passwordKey, create=create)
logger.debug("initialized user wallet %s " % self)
self.__dbaccount = None
self._aliases = None
self._db = None
self.LoadNamedAddresses()
self.initialize_holds()

def initialize_holds(self):
self.LoadHolds()

# Handle EventHub events for SmartContract decorators
@events.on(SmartContractEvent.RUNTIME_NOTIFY)
def call_on_event(sc_event):
# Make sure this event is for this specific smart contract
self.on_notify_sc_event(sc_event)

def on_notify_sc_event(self, sc_event):
if not sc_event.test_mode and isinstance(sc_event.notify_type, bytes):
notify_type = sc_event.notify_type
if notify_type == b'hold_created':
self.process_hold_created_event(sc_event.event_payload[1:])
elif notify_type in [b'hold_cancelled', b'hold_cleaned_up']:
self.process_destroy_hold(notify_type, sc_event.event_payload[1])

def process_hold_created_event(self, payload):
if len(payload) == 4:
vin = payload[0]
from_addr = UInt160(data=payload[1])
to_addr = UInt160(data=payload[2])
amount = int.from_bytes(payload[3], 'little')
v_index = int.from_bytes(vin[32:], 'little')
v_txid = UInt256(data=vin[0:32])
if to_addr.ToBytes() in self._contracts.keys() and from_addr in self._watch_only:
hold, created = VINHold.get_or_create(
Index=v_index, Hash=v_txid.ToBytes(), FromAddress=from_addr.ToBytes(), ToAddress=to_addr.ToBytes(), Amount=amount, IsComplete=False
)
if created:
self.LoadHolds()

def process_destroy_hold(self, destroy_type, vin_to_cancel):
completed = self.LoadCompletedHolds()
for hold in completed:
if hold.Vin == vin_to_cancel:
logger.info('[%s] Deleting hold %s' % (destroy_type, json.dumps(hold.ToJson(), indent=4)))
hold.delete_instance()

def BuildDatabase(self):
self._db = PWDatabase(self._path).DB
Expand Down Expand Up @@ -338,13 +299,6 @@ def LoadTransactions(self):
def LoadNamedAddresses(self):
self._aliases = NamedAddress.select()

def LoadHolds(self):
self._holds = VINHold.filter(IsComplete=False)
return self._holds

def LoadCompletedHolds(self):
return VINHold.filter(IsComplete=True)

@property
def NamedAddr(self):
return self._aliases
Expand Down Expand Up @@ -415,10 +369,6 @@ def OnCoinsChanged(self, added, changed, deleted):
logger.error("[Path: %s ] Could not create coin: %s " % (self._path, e))

for coin in changed:
for hold in self._holds:
if hold.Reference == coin.Reference and coin.State & CoinState.Spent > 0:
hold.IsComplete = True
hold.save()
try:
c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex)
c.State = coin.State
Expand All @@ -427,10 +377,6 @@ def OnCoinsChanged(self, added, changed, deleted):
logger.error("[Path: %s ] could not change coin %s %s (coin to change not found)" % (self._path, coin, e))

for coin in deleted:
for hold in self._holds:
if hold.Reference == coin.Reference:
hold.IsComplete = True
hold.save()
try:
c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex)
c.delete_instance()
Expand Down
21 changes: 0 additions & 21 deletions neo/Prompt/Utils.py
Expand Up @@ -283,27 +283,6 @@ def lookup_addr_str(wallet, addr):
print(e)


def parse_hold_vins(results):
holds = results[0].GetByteArray()
holdlen = len(holds)
numholds = int(holdlen / 33)

vins = []
for i in range(0, numholds):
hstart = i * 33
hend = hstart + 33
item = holds[hstart:hend]

vin_index = item[0]
vin_tx_id = UInt256(data=item[1:])

t_input = TransactionInput(prevHash=vin_tx_id, prevIndex=vin_index)

vins.append(t_input)

return vins


def string_from_fixed8(amount, decimals):
precision_mult = pow(10, decimals)
amount = Decimal(amount) / Decimal(precision_mult)
Expand Down
10 changes: 0 additions & 10 deletions neo/Wallets/Wallet.py
Expand Up @@ -48,10 +48,6 @@ class Wallet:

_current_height = 0

_db_path = _path

_indexedDB = None

_vin_exclude = None

_lock = None # allows locking for threads that may need to access the DB concurrently (e.g. ProcessBlocks and Rebuild)
Expand Down Expand Up @@ -82,12 +78,6 @@ def __init__(self, path, passwordKey, create):
self._contracts = {}
self._coins = {}

if Blockchain.Default() is None:
self._indexedDB = LevelDBBlockchain(settings.chain_leveldb_path)
Blockchain.RegisterBlockchain(self._indexedDB)
else:
self._indexedDB = Blockchain.Default()

self._current_height = 0

self.BuildDatabase()
Expand Down
50 changes: 1 addition & 49 deletions neo/bin/prompt.py
Expand Up @@ -32,8 +32,6 @@
from neo.Prompt.Commands.LoadSmartContract import LoadContract, GatherContractDetails, ImportContractAddr, \
ImportMultiSigContractAddr
from neo.Prompt.Commands.Send import construct_and_send, parse_and_sign
from neo.contrib.nex.withdraw import RequestWithdrawFrom, PrintHolds, DeleteHolds, WithdrawOne, WithdrawAll, \
CancelWithdrawalHolds, ShowCompletedHolds, CleanupCompletedHolds

from neo.Prompt.Commands.Tokens import token_approve_allowance, token_get_allowance, token_send, token_send_from, \
token_mint, token_crowdsale_register, token_history
Expand Down Expand Up @@ -143,13 +141,6 @@ class PromptInterface:
'wallet unspent (neo/gas)',
'wallet split {addr} {asset} {unspent index} {divide into number of vins}',
'wallet close',
'withdraw_request {asset_name} {contract_hash} {to_addr} {amount}',
'withdraw holds # lists all current holds',
'withdraw completed # lists completed holds eligible for cleanup',
'withdraw cancel # cancels current holds',
'withdraw cleanup # cleans up completed holds',
'withdraw # withdraws the first hold availabe',
'withdraw all # withdraw all holds available',
'send {assetId or name} {address} {amount} (--from-addr={addr}) (--fee={priority_fee})',
'sign {transaction in JSON format}',
'testinvoke {contract hash} [{params} or --i] (--attach-neo={amount}, --attach-gas={amount}) (--from-addr={addr}) --no-parse-addr (parse address strings to script hash bytearray)',
Expand Down Expand Up @@ -198,7 +189,7 @@ def get_completer(self):
'sign', 'send', 'withdraw', 'nep2', 'multisig_addr', 'token',
'claim', 'migrate', 'rebuild', 'create_addr', 'delete_addr',
'delete_token', 'alias', 'unspent', 'split', 'close',
'withdraw_reqest', 'holds', 'completed', 'cancel', 'cleanup',
'withdraw_reqest', 'completed', 'cancel', 'cleanup',
'all', 'debugstorage', 'compiler-nep8', ]

if self.Wallet:
Expand Down Expand Up @@ -457,45 +448,6 @@ def do_export(self, arguments):

print("Command export %s not found" % item)

def make_withdraw_request(self, arguments):
if not self.Wallet:
print("Please open a wallet")
return
if len(arguments) == 4:
RequestWithdrawFrom(self.Wallet, arguments[0], arguments[1], arguments[2], arguments[3])
else:
print("Incorrect arg length. Use 'withdraw_request {asset_id} {contract_hash} {to_addr} {amount}'")

def do_withdraw(self, arguments):
if not self.Wallet:
print("Please open a wallet")
return

item = get_arg(arguments, 0)

if item:

if item == 'holds':
PrintHolds(self.Wallet)
elif item == 'delete_holds':
index_to_delete = -1
if get_arg(arguments, 1) and int(get_arg(arguments, 1)) > -1:
index_to_delete = int(get_arg(arguments, 1))
DeleteHolds(self.Wallet, index_to_delete)
elif item == 'cancel_holds':
if len(arguments) > 1:
CancelWithdrawalHolds(self.Wallet, get_arg(arguments, 1))
else:
print("Please specify contract hash to cancel holds for")
elif item == 'completed':
ShowCompletedHolds(self.Wallet)
elif item == 'cleanup':
CleanupCompletedHolds(self.Wallet)
elif item == 'all':
WithdrawAll(self.Wallet)
else:
WithdrawOne(self.Wallet)

def do_notifications(self, arguments):
if NotificationDB.instance() is None:
print("No notification DB Configured")
Expand Down

0 comments on commit bd357f8

Please sign in to comment.