@Test public void transfer() throws Exception { TransferDTO transferDto = CommonRpcOperation.createTransferTx("tNULSeBaMvEtDfvZuukDf2mVyfGo3DdiN8KLRG","tNULSeBaMvEtDfvZuukDf2mVyfGo3DdiN8KLRG",new BigInteger("199800000")); Response cmdResp = ResponseMessageProcessor.requestAndResponse(ModuleE.AC.abbr, "ac_transfer", JSONUtils.json2map(JSONUtils.obj2json(transferDto))); HashMap result = (HashMap) (((HashMap) cmdResp.getResponseData()).get("ac_transfer")); String txDigestHex = (String) result.get(RpcConstant.VALUE); System.out.println(txDigestHex); }
@CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) public Response transfer(Map params) { Chain chain = null; try { if (params == null) { LoggerUtil.LOG.warn("ac_transfer params is null"); throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } JSONUtils.getInstance().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); TransferDTO transferDto = JSONUtils.map2pojo(params, TransferDTO.class); chain = chainManager.getChain(transferDto.getChainId()); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } Transaction tx = transactionService.transfer(chain, transferDto); Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); map.put(RpcConstant.VALUE, tx.getHash().toHex()); return success(map); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } }
TransactionCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) public Response transfer(Map params) { Chain chain = null; try { if (params == null) { LoggerUtil.LOG.warn("ac_transfer params is null"); throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } JSONUtils.getInstance().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); TransferDTO transferDto = JSONUtils.map2pojo(params, TransferDTO.class); chain = chainManager.getChain(transferDto.getChainId()); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } Transaction tx = transactionService.transfer(chain, transferDto); Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); map.put(RpcConstant.VALUE, tx.getHash().toHex()); return success(map); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } } }
TransactionCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) public Response transfer(Map params) { Chain chain = null; try { if (params == null) { LoggerUtil.LOG.warn("ac_transfer params is null"); throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } JSONUtils.getInstance().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); TransferDTO transferDto = JSONUtils.map2pojo(params, TransferDTO.class); chain = chainManager.getChain(transferDto.getChainId()); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } Transaction tx = transactionService.transfer(chain, transferDto); Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); map.put(RpcConstant.VALUE, tx.getHash().toHex()); return success(map); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } }  }
TransactionCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) public Response transfer(Map params) { Chain chain = null; try { if (params == null) { LoggerUtil.LOG.warn("ac_transfer params is null"); throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } JSONUtils.getInstance().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); TransferDTO transferDto = JSONUtils.map2pojo(params, TransferDTO.class); chain = chainManager.getChain(transferDto.getChainId()); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } Transaction tx = transactionService.transfer(chain, transferDto); Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); map.put(RpcConstant.VALUE, tx.getHash().toHex()); return success(map); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } }  @CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) Response transfer(Map params); @CmdAnnotation(cmd = "ac_createMultiSignTransfer", version = 1.0, description = "创建多签地址转账交易/create multi sign transfer") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = BaseCoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = MultiSignCoinToDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注"), @Parameter(parameterName = "signAddress", parameterType = "String", canNull = true, parameterDes = "第一个签名账户地址(不填则只创建交易不签名)"), @Parameter(parameterName = "signPassword", parameterType = "String", canNull = true, parameterDes = "第一个签名账户密码(不填则只创建交易不签名)") }) @ResponseData(name = "返回值", description = "返回一个Map,包含三个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "tx", description = "完整交易序列化字符串,如果交易没达到最小签名数可继续签名"), @Key(name = "txHash", description = "交易hash"), @Key(name = "completed", valueType = boolean.class, description = "true:交易已完成(已广播),false:交易没完成,没有达到最小签名数") })) Response multiSignTransfer(Map params); @CmdAnnotation(cmd = "ac_signMultiSignTransaction", version = 1.0, description = "多签交易签名/sign MultiSign Transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "tx", parameterType = "String", parameterDes = "交易数据字符串"), @Parameter(parameterName = "signAddress", parameterType = "String", parameterDes = "签名账户地址"), @Parameter(parameterName = "signPassword", parameterType = "String", parameterDes = "签名账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map,包含三个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "tx", description = "完整交易序列化字符串,如果交易没达到最小签名数可继续签名"), @Key(name = "txHash", description = "交易hash"), @Key(name = "completed", valueType = boolean.class, description = "true:交易已完成(已广播),false:交易没完成,没有达到最小签名数") })) Response signMultiSignTransaction(Map params); }
TransactionCmd extends BaseCmd { @CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) public Response transfer(Map params) { Chain chain = null; try { if (params == null) { LoggerUtil.LOG.warn("ac_transfer params is null"); throw new NulsRuntimeException(AccountErrorCode.NULL_PARAMETER); } JSONUtils.getInstance().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); TransferDTO transferDto = JSONUtils.map2pojo(params, TransferDTO.class); chain = chainManager.getChain(transferDto.getChainId()); if (null == chain) { throw new NulsRuntimeException(AccountErrorCode.CHAIN_NOT_EXIST); } Transaction tx = transactionService.transfer(chain, transferDto); Map<String, String> map = new HashMap<>(AccountConstant.INIT_CAPACITY_2); map.put(RpcConstant.VALUE, tx.getHash().toHex()); return success(map); } catch (NulsRuntimeException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (NulsException e) { errorLogProcess(chain, e); return failed(e.getErrorCode()); } catch (Exception e) { errorLogProcess(chain, e); return failed(AccountErrorCode.SYS_UNKOWN_EXCEPTION); } }  @CmdAnnotation(cmd = "ac_transfer", version = 1.0, description = "创建普通转账交易/create transfer transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = CoinDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注") }) @ResponseData(name = "返回值", description = "返回一个Map", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = RpcConstant.VALUE, description = "交易hash") })) Response transfer(Map params); @CmdAnnotation(cmd = "ac_createMultiSignTransfer", version = 1.0, description = "创建多签地址转账交易/create multi sign transfer") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "inputs", requestType = @TypeDescriptor(value = List.class, collectionElement = BaseCoinDTO.class), parameterDes = "交易支付方数据"), @Parameter(parameterName = "outputs", requestType = @TypeDescriptor(value = List.class, collectionElement = MultiSignCoinToDTO.class), parameterDes = "交易接受方数据"), @Parameter(parameterName = "remark", parameterType = "String", parameterDes = "交易备注"), @Parameter(parameterName = "signAddress", parameterType = "String", canNull = true, parameterDes = "第一个签名账户地址(不填则只创建交易不签名)"), @Parameter(parameterName = "signPassword", parameterType = "String", canNull = true, parameterDes = "第一个签名账户密码(不填则只创建交易不签名)") }) @ResponseData(name = "返回值", description = "返回一个Map,包含三个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "tx", description = "完整交易序列化字符串,如果交易没达到最小签名数可继续签名"), @Key(name = "txHash", description = "交易hash"), @Key(name = "completed", valueType = boolean.class, description = "true:交易已完成(已广播),false:交易没完成,没有达到最小签名数") })) Response multiSignTransfer(Map params); @CmdAnnotation(cmd = "ac_signMultiSignTransaction", version = 1.0, description = "多签交易签名/sign MultiSign Transaction") @Parameters(value = { @Parameter(parameterName = "chainId", requestType = @TypeDescriptor(value = int.class), parameterDes = "链id"), @Parameter(parameterName = "tx", parameterType = "String", parameterDes = "交易数据字符串"), @Parameter(parameterName = "signAddress", parameterType = "String", parameterDes = "签名账户地址"), @Parameter(parameterName = "signPassword", parameterType = "String", parameterDes = "签名账户密码") }) @ResponseData(name = "返回值", description = "返回一个Map,包含三个key", responseType = @TypeDescriptor(value = Map.class, mapKeys = { @Key(name = "tx", description = "完整交易序列化字符串,如果交易没达到最小签名数可继续签名"), @Key(name = "txHash", description = "交易hash"), @Key(name = "completed", valueType = boolean.class, description = "true:交易已完成(已广播),false:交易没完成,没有达到最小签名数") })) Response signMultiSignTransaction(Map params);  }