public TempStateStore invoke(TransactionHusk tx, TransactionReceipt txReceipt, Store origin) { // Find invoke method and invoke // validation method TempStateStore txState = new TempStateStore(origin); try { // transaction is multiple method for (JsonElement transactionElement: JsonUtil.parseJsonArray(tx.getBody())) { JsonObject txBody = transactionElement.getAsJsonObject(); // check contract Version ContractId txContractId = ContractId.of(txBody.get("contractId").getAsString()); RuntimeContractWrap wrap = contracts.get(txContractId); TempStateStore txElementState = wrap.invokeTransaction(txBody, txReceipt, txState); if(txReceipt.isSuccess()) { txState.putAll(txElementState.changeValues()); } } } catch (Throwable e) { txReceipt.setStatus(ExecuteStatus.ERROR); JsonObject errorLog = new JsonObject(); errorLog.addProperty("error", e.getMessage()); txReceipt.addLog(errorLog); } return txState; }
public TempStateStore invokeTransaction(JsonObject txBody, TransactionReceipt txReceipt, Store origin) throws InvocationTargetException, IllegalAccessException { // set State Store TempStateStore store = new TempStateStore(origin); // set store to contract ContractUtils.updateContractFields(contract, stateField, store); transactionReceiptField.set(contract, txReceipt); // TODO Check Transaction has contractID String methodName = txBody.get("method").getAsString(); ContractMethod method = invokeMethods.get(methodName); // filter method exist if(method == null) { txReceipt.setStatus(ExecuteStatus.ERROR); txReceipt.addLog(errorLog("method is not exist")); return store; } // check exist params if(txBody.has("params") && method.isParams()) { JsonObject params = txBody.getAsJsonObject("params"); method.getMethod().invoke(contract, params); } else if (!method.isParams()) { method.getMethod().invoke(contract); } else { txReceipt.setStatus(ExecuteStatus.ERROR); txReceipt.addLog(errorLog("params is not exist")); return store; } return store; }
@Test public void init() { JsonObject originObj = new JsonObject(); originObj.addProperty("test", "origin"); stateStore.put("TEST", originObj); TempStateStore store = new TempStateStore(stateStore); assert store.get("TEST").equals(originObj); JsonObject testObj = new JsonObject(); testObj.addProperty("test", "yes"); store.put("TEST", testObj); assert store.get("TEST").equals(testObj); store.close(); assert store.get("TEST").equals(originObj); } }
TempStateStore blockState = new TempStateStore(stateStore); for(TransactionHusk tx: block.getBody()) { TransactionReceipt txReceipt = new TransactionReceiptImpl(tx);