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

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
localhuman committed Oct 18, 2017
2 parents cdec009 + a203107 commit 5cfdfc7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
93 changes: 93 additions & 0 deletions neo/Prompt/Commands/BuildNRun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from neo.Prompt.Utils import get_arg
from neo.Prompt.Commands.LoadSmartContract import GatherLoadedContractParams
from neo.Prompt.Commands.Invoke import test_deploy_and_invoke
from neo.Fixed8 import Fixed8
from boa.compiler import Compiler
import binascii
import traceback

def LoadAndRun(arguments, wallet):

path = get_arg(arguments)

try:

with open(path, 'rb') as f:

content = f.read()

try:
content = binascii.unhexlify(content)
except Exception as e:
pass

script = content

print("arguments.... %s " % arguments)
DoRun(script, arguments, wallet, path)

except Exception as e:
print("couldnt load script %s " % e)



def BuildAndRun(arguments, wallet):
path = get_arg(arguments)

try:
contract_script = Compiler.instance().load_and_save(path)

newpath = path.replace('.py' ,'.avm')
print("Saved output to %s " % newpath)

DoRun(contract_script,arguments,wallet, path)

except Exception as e:
print("couldn compile %s " % e)


def DoRun(contract_script, arguments, wallet, path):


try:

test = get_arg(arguments, 1)

if test is not None and test == 'test':

if wallet is not None:

f_args = arguments[2:]
i_args = arguments[5:]

script = GatherLoadedContractParams(f_args, contract_script)

tx ,result,total_ops = test_deploy_and_invoke(script, i_args, wallet)
i_args.reverse()

if tx is not None and result is not None:
print("\n-----------------------------------------------------------")
print("Calling %s with arguments %s " % (path, i_args))
print("Test deploy invoke successful")
print("Used total of %s operations " % total_ops)
print("Result %s " % result)
print("Invoke TX gas cost: %s " % (tx.Gas.value / Fixed8.D))
print("-------------------------------------------------------------\n")
return
else:
print("test ivoke failed")
print("tx is, results are %s %s " % (tx, result))
return



else:

print("please open a wallet to test built contract")



except Exception as e:
print("could not bulid %s " % e)
traceback.print_stack()
traceback.print_exc()
13 changes: 9 additions & 4 deletions prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
import json
import logging
import datetime
import time
import os
from neo.IO.MemoryStream import StreamManager
from neo.Network.NodeLeader import NodeLeader
import resource

from neo.Core.Blockchain import Blockchain
from neo.Core.TX.Transaction import Transaction,ContractTransaction,TransactionOutput
from neo.Implementations.Wallets.peewee.UserWallet import UserWallet
from neo.Implementations.Blockchains.LevelDB.LevelDBBlockchain import LevelDBBlockchain
from neo.SmartContract.ContractParameterContext import ContractParametersContext
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,ImportContractAddr
from neo.Prompt.Commands.Send import construct_and_send
from neo.Prompt.Commands.Wallet import DeleteAddress
Expand Down Expand Up @@ -286,7 +283,11 @@ def do_import(self, arguments):
print("please specify something to import")
return

def do_build(self, arguments):
BuildAndRun(arguments, self.Wallet)

def do_load_n_run(self, arguments):
LoadAndRun(arguments, self.Wallet)

def do_export(self, arguments):
item = get_arg(arguments)
Expand Down Expand Up @@ -713,6 +714,10 @@ def run(self):
self.do_create(arguments)
elif command == 'open':
self.do_open(arguments)
elif command == 'build':
self.do_build(arguments)
elif command == 'load_run':
self.do_load_n_run(arguments)
elif command == 'import':
self.do_import(arguments)
elif command == 'export':
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ incremental==17.5.0
memory-profiler==0.47
mmh3==2.4
mpmath==0.19
neo-boa==0.1.5
numpy==1.13.1
peewee==2.10.1
plyvel==0.9
Expand Down

0 comments on commit 5cfdfc7

Please sign in to comment.