@@ -860,7 +860,8 @@ public Transaction deployContract(CreateSmartContract createSmartContract,
860860
861861 public Transaction triggerContract (TriggerSmartContract triggerSmartContract ,
862862 TransactionCapsule trxCap , Builder builder ,
863- Return .Builder retBuilder ) throws ContractValidateException {
863+ Return .Builder retBuilder )
864+ throws ContractValidateException , ContractExeException , HeaderNotFound {
864865
865866 ContractStore contractStore = dbManager .getContractStore ();
866867 byte [] contractAddress = triggerSmartContract .getContractAddress ().toByteArray ();
@@ -869,54 +870,46 @@ public Transaction triggerContract(TriggerSmartContract triggerSmartContract,
869870 throw new ContractValidateException ("No contract or not a smart contract" );
870871 }
871872
872- try {
873- byte [] selector = getSelector (triggerSmartContract .getData ().toByteArray ());
873+ byte [] selector = getSelector (triggerSmartContract .getData ().toByteArray ());
874874
875- boolean constant = isConstant (abi , selector );
876- if (!constant ) {
877- return trxCap .getInstance ();
878- } else {
879- if (!Args .getInstance ().isSupportConstant ()) {
880- throw new ContractValidateException ("this node don't support constant" );
881- }
882- DepositImpl deposit = DepositImpl .createRoot (dbManager );
875+ if (!isConstant (abi , selector )) {
876+ return trxCap .getInstance ();
877+ } else {
878+ if (!Args .getInstance ().isSupportConstant ()) {
879+ throw new ContractValidateException ("this node don't support constant" );
880+ }
881+ DepositImpl deposit = DepositImpl .createRoot (dbManager );
883882
884- Block headBlock ;
885- List <BlockCapsule > blockCapsuleList = dbManager .getBlockStore ().getBlockByLatestNum (1 );
886- if (CollectionUtils .isEmpty (blockCapsuleList )) {
887- throw new HeaderNotFound ("latest block not found" );
888- } else {
889- headBlock = blockCapsuleList .get (0 ).getInstance ();
890- }
883+ Block headBlock ;
884+ List <BlockCapsule > blockCapsuleList = dbManager .getBlockStore ().getBlockByLatestNum (1 );
885+ if (CollectionUtils .isEmpty (blockCapsuleList )) {
886+ throw new HeaderNotFound ("latest block not found" );
887+ } else {
888+ headBlock = blockCapsuleList .get (0 ).getInstance ();
889+ }
891890
892- Runtime runtime = new Runtime (trxCap .getInstance (), new BlockCapsule (headBlock ), deposit ,
893- new ProgramInvokeFactoryImpl ());
894- runtime .execute ();
895- runtime .go ();
896- runtime .finalization ();
897- // TODO exception
898- if (runtime .getResult ().getException () != null ) {
891+ Runtime runtime = new Runtime (trxCap .getInstance (), new BlockCapsule (headBlock ), deposit ,
892+ new ProgramInvokeFactoryImpl ());
893+ runtime .execute ();
894+ runtime .go ();
895+ runtime .finalization ();
896+ // TODO exception
897+ if (runtime .getResult ().getException () != null ) {
899898// runtime.getResult().getException().printStackTrace();
900- throw new RuntimeException ("Runtime exe failed!" );
901- }
899+ throw new RuntimeException ("Runtime exe failed!" );
900+ }
902901
903- ProgramResult result = runtime .getResult ();
904- TransactionResultCapsule ret = new TransactionResultCapsule ();
902+ ProgramResult result = runtime .getResult ();
903+ TransactionResultCapsule ret = new TransactionResultCapsule ();
905904
906- builder .addConstantResult (ByteString .copyFrom (result .getHReturn ()));
907- ret .setStatus (0 , code .SUCESS );
908- if (StringUtils .isNoneEmpty (runtime .getRuntimeError ())) {
909- ret .setStatus (0 , code .FAILED );
910- retBuilder .setMessage (ByteString .copyFromUtf8 (runtime .getRuntimeError ())).build ();
911- }
912- trxCap .setResult (ret );
913- return trxCap .getInstance ();
905+ builder .addConstantResult (ByteString .copyFrom (result .getHReturn ()));
906+ ret .setStatus (0 , code .SUCESS );
907+ if (StringUtils .isNoneEmpty (runtime .getRuntimeError ())) {
908+ ret .setStatus (0 , code .FAILED );
909+ retBuilder .setMessage (ByteString .copyFromUtf8 (runtime .getRuntimeError ())).build ();
914910 }
915- } catch (ContractValidateException e ) {
916- throw e ;
917- } catch (Exception e ) {
918- logger .error (e .getMessage ());
919- return null ;
911+ trxCap .setResult (ret );
912+ return trxCap .getInstance ();
920913 }
921914 }
922915
@@ -948,14 +941,11 @@ private static byte[] getSelector(byte[] data) {
948941 return ret ;
949942 }
950943
951- private static boolean isConstant (SmartContract .ABI abi , byte [] selector ) throws Exception {
944+ private static boolean isConstant (SmartContract .ABI abi , byte [] selector ) {
952945
953- if (selector == null || abi .getEntrysList ().size () == 0 ) {
946+ if (selector == null || selector . length != 4 || abi .getEntrysList ().size () == 0 ) {
954947 return false ;
955948 }
956- if (selector .length != 4 ) {
957- throw new Exception ("Selector's length or selector itself is invalid" );
958- }
959949
960950 for (int i = 0 ; i < abi .getEntrysCount (); i ++) {
961951 ABI .Entry entry = abi .getEntrys (i );
0 commit comments