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

Commit

Permalink
merge tx invoke fee fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Oct 9, 2017
1 parent f042810 commit 5d54488
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
25 changes: 17 additions & 8 deletions neo/Prompt/Commands/Invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
import pdb
import json

def InvokeContract(wallet, tx):
def InvokeContract(wallet, tx, fee=Fixed8.Zero()):


wallet_tx = wallet.MakeTransaction(tx=tx)
wallet_tx = wallet.MakeTransaction(tx=tx,fee=fee)

if wallet_tx:

Expand Down Expand Up @@ -211,17 +211,24 @@ def test_invoke(script, wallet, outputs):
consumed = engine.GasConsumed() - Fixed8.FromDecimal(10)
consumed.value = int(consumed.value)

net_fee = None
tx_gas = None

if consumed < Fixed8.One():
consumed = Fixed8.One()
net_fee = Fixed8.FromDecimal(.001)
tx_gas = Fixed8.Zero()
else:
tx_gas = consumed
net_fee = Fixed8.Zero()

#set the amount of gas the tx will need
wallet_tx.Gas = consumed
wallet_tx.Gas = tx_gas

#reset the wallet outputs
wallet_tx.outputs = outputs
wallet_tx.Attributes = []

return wallet_tx, engine.EvaluationStack.Items
return wallet_tx, net_fee, engine.EvaluationStack.Items, engine.ops_processed
else:
print("error executing contract.....")
# tx.Gas = Fixed8.One()
Expand Down Expand Up @@ -342,7 +349,6 @@ def test_deploy_and_invoke(deploy_script, invoke_args, wallet):
script_hash=contract_state.Code.ScriptHash(),
)
outputs.append(output)
print("NEO TO ATTACH: %s " % outputs)

if gas_to_attach:
output = TransactionOutput(AssetId=Blockchain.SystemCoin().Hash,
Expand Down Expand Up @@ -396,13 +402,16 @@ def test_deploy_and_invoke(deploy_script, invoke_args, wallet):
consumed.value = int(consumed.value)

if consumed < Fixed8.One():
consumed = Fixed8.One()
consumed = Fixed8.FromDecimal(.001)


total_ops = engine.ops_processed

# set the amount of gas the tx will need
itx.Gas = consumed
itx.Attributes = []
result = engine.ResultsForCode(contract_state.Code)
return itx, result
return itx, result, total_ops
else:
print("error executing invoke contract...")

Expand Down
4 changes: 4 additions & 0 deletions neo/SmartContract/StateReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,12 @@ def Output_GetScriptHash(self, engine):

def Account_GetScriptHash(self, engine):

print("getting account script hash!!!! ")
account = engine.EvaluationStack.Pop().GetInterface('neo.Core.State.AccountState.AccountState')
print("acccount isssss...... %s " % account)
if account is None:
return False
print("pushing account script hash onto account....")
engine.EvaluationStack.PushT(account.ScriptHash.ToArray())
return True

Expand Down Expand Up @@ -695,6 +698,7 @@ def Storage_Get(self, engine):
context = item.GetInterface('neo.SmartContract.StorageContext.StorageContext')
shash = context.ScriptHash
except Exception as e:
print("could not get storage context %s " % e)
return False


Expand Down
4 changes: 4 additions & 0 deletions neo/VM/ExecutionEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ExecutionEngine():
_AltStack = None


ops_processed = 0

@property
def ScriptContainer(self):
Expand Down Expand Up @@ -80,6 +81,7 @@ def __init__(self, container=None, crypto=None, table=None, service = None):
self._EvaluationStack = RandomAccessStack(name='Evaluation')
self._AltStack = RandomAccessStack(name='Alt')

self.ops_processed = 0

def AddBreakPoint(self, position):
self.CurrentContext.Breakpoints.add(position)
Expand Down Expand Up @@ -798,6 +800,8 @@ def StepInto(self):
# print("%s -> %s" % (op, opname))
# print("-----------------------------------")

self.ops_processed += 1

try:
self.ExecuteOp(op, self.CurrentContext)
except Exception as e:
Expand Down
19 changes: 13 additions & 6 deletions prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from neo.Wallets.KeyPair import KeyPair
from neo.Network.NodeLeader import NodeLeader
from neo.Prompt.Commands.Invoke import InvokeContract,TestInvokeContract,test_invoke,test_deploy_and_invoke
#from neo.Prompt.Commands.BuildNRun import BuildAndRun,LoadAndRun
from neo.Prompt.Commands.LoadSmartContract import LoadContract,GatherContractDetails,GatherLoadedContractParams
from neo.Prompt.Utils import get_arg
from neo.Prompt.Notify import SubscribeNotifications
Expand All @@ -41,7 +40,6 @@
from prompt_toolkit.contrib.completers import WordCompleter
from prompt_toolkit.history import InMemoryHistory

#from boa.boa import Compiler

logname = 'prompt.log'
logging.basicConfig(
Expand Down Expand Up @@ -89,6 +87,7 @@ class PromptInterface(object):
_wallet_send_tx = None

_invoke_test_tx = None
_invoke_test_tx_fee = None

Wallet = None

Expand Down Expand Up @@ -634,14 +633,17 @@ def load_smart_contract(self, args):

if contract_script is not None:

tx, results = test_invoke(contract_script, self.Wallet, [])
tx, fee, results, num_ops = test_invoke(contract_script, self.Wallet, [])

if tx is not None and results is not None:
self._invoke_test_tx = tx
self._invoke_test_tx_fee = fee
print("\n-------------------------------------------------------------------------------------------------------------------------------------")
print("Test deploy invoke successful")
print("Total operations executed: %s " % num_ops)
print("Results %s " % [str(item) for item in results])
print("Deploy Invoke TX gas cost: %s " % (int(tx.Gas.value / Fixed8.D)))
print("Deploy Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D))
print("Deploy Invoke TX Fee: %s " % (fee.value / Fixed8.D))
print("-------------------------------------------------------------------------------------------------------------------------------------\n")
print("You may now deploy this contract on the blockchain by using the 'invoke' command with no arguments or type 'cancel' to cancel deploy\n")
return
Expand All @@ -652,21 +654,25 @@ def load_smart_contract(self, args):

def test_invoke_contract(self, args):
self._invoke_test_tx = None
self._invoke_test_tx_fee = None

if not self.Wallet:
print("please open a wallet")
return


if args and len(args) > 0:
tx, results = TestInvokeContract(self.Wallet, args)
tx, fee, results,num_ops = TestInvokeContract(self.Wallet, args)

if tx is not None and results is not None:
self._invoke_test_tx = tx
self._invoke_test_tx_fee = fee
print("\n-------------------------------------------------------------------------------------------------------------------------------------")
print("Test invoke successful")
print("Total operations: %s " % num_ops)
print("Results %s " % [str(item) for item in results])
print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D))
print("Invoke TX Fee: %s " % (fee.value / Fixed8.D))
print("-------------------------------------------------------------------------------------------------------------------------------------\n")
print("You may now invoke this on the blockchain by using the 'invoke' command with no arguments or type 'cancel' to cancel invoke\n")
return
Expand All @@ -682,9 +688,10 @@ def invoke_contract(self, args):
print("Please test your invoke before deploying it with the 'testinvoke {contracthash} *args' command")
return

result = InvokeContract(self.Wallet, self._invoke_test_tx)
result = InvokeContract(self.Wallet, self._invoke_test_tx, self._invoke_test_tx_fee)

self._invoke_test_tx = None
self._invoke_test_tx_fee = None
return

def cancel_operations(self):
Expand Down

0 comments on commit 5d54488

Please sign in to comment.