@@ -834,7 +834,8 @@ public Transaction deployContract(CreateSmartContract createSmartContract,
834834
835835 public Transaction triggerContract (TriggerSmartContract triggerSmartContract ,
836836 TransactionCapsule trxCap , Builder builder ,
837- Return .Builder retBuilder ) throws ContractValidateException {
837+ Return .Builder retBuilder )
838+ throws ContractValidateException , ContractExeException , HeaderNotFound {
838839
839840 ContractStore contractStore = dbManager .getContractStore ();
840841 byte [] contractAddress = triggerSmartContract .getContractAddress ().toByteArray ();
@@ -843,54 +844,46 @@ public Transaction triggerContract(TriggerSmartContract triggerSmartContract,
843844 throw new ContractValidateException ("No contract or not a smart contract" );
844845 }
845846
846- try {
847- byte [] selector = getSelector (triggerSmartContract .getData ().toByteArray ());
847+ byte [] selector = getSelector (triggerSmartContract .getData ().toByteArray ());
848848
849- boolean constant = isConstant (abi , selector );
850- if (!constant ) {
851- return trxCap .getInstance ();
852- } else {
853- if (!Args .getInstance ().isSupportConstant ()) {
854- throw new ContractValidateException ("this node don't support constant" );
855- }
856- DepositImpl deposit = DepositImpl .createRoot (dbManager );
849+ if (!isConstant (abi , selector )) {
850+ return trxCap .getInstance ();
851+ } else {
852+ if (!Args .getInstance ().isSupportConstant ()) {
853+ throw new ContractValidateException ("this node don't support constant" );
854+ }
855+ DepositImpl deposit = DepositImpl .createRoot (dbManager );
857856
858- Block headBlock ;
859- List <BlockCapsule > blockCapsuleList = dbManager .getBlockStore ().getBlockByLatestNum (1 );
860- if (CollectionUtils .isEmpty (blockCapsuleList )) {
861- throw new HeaderNotFound ("latest block not found" );
862- } else {
863- headBlock = blockCapsuleList .get (0 ).getInstance ();
864- }
857+ Block headBlock ;
858+ List <BlockCapsule > blockCapsuleList = dbManager .getBlockStore ().getBlockByLatestNum (1 );
859+ if (CollectionUtils .isEmpty (blockCapsuleList )) {
860+ throw new HeaderNotFound ("latest block not found" );
861+ } else {
862+ headBlock = blockCapsuleList .get (0 ).getInstance ();
863+ }
865864
866- Runtime runtime = new Runtime (trxCap .getInstance (), new BlockCapsule (headBlock ), deposit ,
867- new ProgramInvokeFactoryImpl ());
868- runtime .execute ();
869- runtime .go ();
870- runtime .finalization ();
871- // TODO exception
872- if (runtime .getResult ().getException () != null ) {
865+ Runtime runtime = new Runtime (trxCap .getInstance (), new BlockCapsule (headBlock ), deposit ,
866+ new ProgramInvokeFactoryImpl ());
867+ runtime .execute ();
868+ runtime .go ();
869+ runtime .finalization ();
870+ // TODO exception
871+ if (runtime .getResult ().getException () != null ) {
873872// runtime.getResult().getException().printStackTrace();
874- throw new RuntimeException ("Runtime exe failed!" );
875- }
873+ throw new RuntimeException ("Runtime exe failed!" );
874+ }
876875
877- ProgramResult result = runtime .getResult ();
878- TransactionResultCapsule ret = new TransactionResultCapsule ();
876+ ProgramResult result = runtime .getResult ();
877+ TransactionResultCapsule ret = new TransactionResultCapsule ();
879878
880- builder .addConstantResult (ByteString .copyFrom (result .getHReturn ()));
881- ret .setStatus (0 , code .SUCESS );
882- if (StringUtils .isNoneEmpty (runtime .getRuntimeError ())) {
883- ret .setStatus (0 , code .FAILED );
884- retBuilder .setMessage (ByteString .copyFromUtf8 (runtime .getRuntimeError ())).build ();
885- }
886- trxCap .setResult (ret );
887- return trxCap .getInstance ();
879+ builder .addConstantResult (ByteString .copyFrom (result .getHReturn ()));
880+ ret .setStatus (0 , code .SUCESS );
881+ if (StringUtils .isNoneEmpty (runtime .getRuntimeError ())) {
882+ ret .setStatus (0 , code .FAILED );
883+ retBuilder .setMessage (ByteString .copyFromUtf8 (runtime .getRuntimeError ())).build ();
888884 }
889- } catch (ContractValidateException e ) {
890- throw e ;
891- } catch (Exception e ) {
892- logger .error (e .getMessage ());
893- return null ;
885+ trxCap .setResult (ret );
886+ return trxCap .getInstance ();
894887 }
895888 }
896889
@@ -922,14 +915,11 @@ private static byte[] getSelector(byte[] data) {
922915 return ret ;
923916 }
924917
925- private static boolean isConstant (SmartContract .ABI abi , byte [] selector ) throws Exception {
918+ private static boolean isConstant (SmartContract .ABI abi , byte [] selector ) {
926919
927- if (selector == null || abi .getEntrysList ().size () == 0 ) {
920+ if (selector == null || selector . length != 4 || abi .getEntrysList ().size () == 0 ) {
928921 return false ;
929922 }
930- if (selector .length != 4 ) {
931- throw new Exception ("Selector's length or selector itself is invalid" );
932- }
933923
934924 for (int i = 0 ; i < abi .getEntrysCount (); i ++) {
935925 ABI .Entry entry = abi .getEntrys (i );
0 commit comments