use of io.nuls.account.service.intf.AccountService in project nuls by nuls-io.
the class UtxoTransactionTool method createTransferTx.
public TransferTransaction createTransferTx(CoinTransferData transferData, String password, String remark) throws Exception {
if (transferData.getFrom().isEmpty()) {
throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
}
TransferTransaction tx = new TransferTransaction(transferData, password);
if (StringUtils.isNotBlank(remark)) {
tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCODING));
}
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
AccountService accountService = getAccountService();
Account account = accountService.getAccount(transferData.getFrom().get(0));
tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
return tx;
}
use of io.nuls.account.service.intf.AccountService in project nuls by nuls-io.
the class UtxoTransactionTool method createLockNulsTx.
public LockNulsTransaction createLockNulsTx(CoinTransferData transferData, String password, String remark) throws Exception {
LockNulsTransaction tx = new LockNulsTransaction(transferData, password);
if (StringUtils.isNotBlank(remark)) {
tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCODING));
}
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
AccountService accountService = getAccountService();
if (transferData.getFrom().isEmpty()) {
throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
}
Account account = accountService.getAccount(transferData.getFrom().get(0));
tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
return tx;
}
use of io.nuls.account.service.intf.AccountService in project nuls by nuls-io.
the class GenesisBlock method initGengsisTxs.
private void initGengsisTxs(Map<String, Object> jsonMap) {
List<Map<String, Object>> list = (List<Map<String, Object>>) jsonMap.get(CONFIG_FILED_TXS);
if (null == list || list.isEmpty()) {
throw new NulsRuntimeException(ErrorCode.CONFIG_ERROR);
}
CoinTransferData data = new CoinTransferData(OperationType.COIN_BASE, Na.ZERO);
data.setPriKey(Hex.decode(priKey));
Na total = Na.ZERO;
for (Map<String, Object> map : list) {
String address = (String) map.get(CONFIG_FILED_ADDRESS);
AssertUtil.canNotEmpty(address, ErrorCode.NULL_PARAMETER);
Integer nuls = (Integer) map.get(CONFIG_FILED_NULS);
AssertUtil.canNotEmpty(nuls, ErrorCode.NULL_PARAMETER);
Integer height = (Integer) map.get(CONFIG_FILED_UNLOCK_HEIGHT);
Coin coin = new Coin();
coin.setNa(Na.parseNuls(nuls));
coin.setUnlockTime(0);
if (height == null) {
coin.setUnlockTime(0);
} else {
coin.setUnlockHeight(height.longValue());
}
data.addTo(address, coin);
total = total.add(coin.getNa());
}
data.setTotalNa(total);
CoinBaseTransaction tx = null;
try {
tx = new CoinBaseTransaction(data, null);
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
tx.setTime(this.blockTime);
tx.setFee(Na.ZERO);
try {
tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
} catch (IOException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
P2PKHScriptSig p2PKHScriptSig = new P2PKHScriptSig();
Account account = null;
try {
account = AccountTool.createAccount(priKey);
} catch (NulsException e) {
e.printStackTrace();
}
AccountService accountService = NulsContext.getServiceBean(AccountService.class);
P2PKHScriptSig scriptSig = null;
try {
scriptSig = accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, "");
} catch (NulsException e) {
e.printStackTrace();
}
try {
tx.setScriptSig(scriptSig.serialize());
} catch (IOException e) {
e.printStackTrace();
}
List<Transaction> txlist = new ArrayList<>();
// tx.setStatus(TxStatusEnum.AGREED);
txlist.add(tx);
setTxs(txlist);
}
Aggregations