Search in sources :

Example 6 with TransactionEvent

use of io.nuls.ledger.event.TransactionEvent in project nuls by nuls-io.

the class AccountServiceImpl method setAlias.

@Override
public Result setAlias(String address, String password, String alias) {
    Account account = getAccount(address);
    if (account == null) {
        return new Result(false, ErrorCode.ACCOUNT_NOT_EXIST, null);
    }
    if (StringUtils.isNotBlank(account.getAlias())) {
        return new Result(false, "Alias has been set up");
    }
    if (!StringUtils.validAlias(alias)) {
        return new Result(false, "The alias is between 3 to 20 characters");
    }
    try {
        TransactionEvent event = new TransactionEvent();
        CoinTransferData coinData = new CoinTransferData(OperationType.TRANSFER, AccountConstant.ALIAS_NA, address, ledgerService.getTxFee(TransactionConstant.TX_TYPE_SET_ALIAS));
        AliasTransaction aliasTx = new AliasTransaction(coinData, password, new Alias(address, alias));
        aliasTx.setHash(NulsDigestData.calcDigestData(aliasTx.serialize()));
        aliasTx.setScriptSig(createP2PKHScriptSigFromDigest(aliasTx.getHash(), account, password).serialize());
        ValidateResult validate = aliasTx.verify();
        if (validate.isFailed()) {
            return new Result(false, validate.getMessage());
        }
        event.setEventBody(aliasTx);
        eventBroadcaster.broadcastAndCache(event, true);
        SetAliasNotice notice = new SetAliasNotice();
        notice.setEventBody(aliasTx);
        eventBroadcaster.publishToLocal(notice);
    } catch (Exception e) {
        Log.error(e);
        return new Result(false, e.getMessage());
    }
    return new Result(true, "OK");
}
Also used : Account(io.nuls.account.entity.Account) AliasTransaction(io.nuls.account.entity.tx.AliasTransaction) TransactionEvent(io.nuls.ledger.event.TransactionEvent) CoinTransferData(io.nuls.ledger.entity.params.CoinTransferData) Alias(io.nuls.account.entity.Alias) ValidateResult(io.nuls.core.validate.ValidateResult) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) ValidateResult(io.nuls.core.validate.ValidateResult) Result(io.nuls.core.chain.entity.Result)

Example 7 with TransactionEvent

use of io.nuls.ledger.event.TransactionEvent in project nuls by nuls-io.

the class UtxoLedgerServiceImpl method transfer.

private Result transfer(CoinTransferData coinData, String password, String remark) {
    TransferTransaction tx = null;
    try {
        tx = UtxoTransactionTool.getInstance().createTransferTx(coinData, password, remark);
        ValidateResult result = tx.verify();
        if (result.isFailed()) {
            throw new NulsException(result.getErrorCode());
        }
        byte[] txbytes = tx.serialize();
        TransferTransaction new_tx = new NulsByteBuffer(txbytes).readNulsData(new TransferTransaction());
        result = new_tx.verify();
        if (result.isFailed()) {
            throw new NulsException(result.getErrorCode());
        }
        TransactionEvent event = new TransactionEvent();
        event.setEventBody(tx);
        eventBroadcaster.broadcastAndCacheAysn(event, true);
    } catch (Exception e) {
        Log.error(e);
        return new Result(false, e.getMessage());
    }
    return new Result(true, "OK", tx.getHash().getDigestHex());
}
Also used : TransactionEvent(io.nuls.ledger.event.TransactionEvent) NulsException(io.nuls.core.exception.NulsException) ValidateResult(io.nuls.core.validate.ValidateResult) TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer) ValidateResult(io.nuls.core.validate.ValidateResult)

Aggregations

NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)7 TransactionEvent (io.nuls.ledger.event.TransactionEvent)7 NulsException (io.nuls.core.exception.NulsException)6 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)5 ValidateResult (io.nuls.core.validate.ValidateResult)4 IOException (java.io.IOException)4 Coin (io.nuls.ledger.entity.params.Coin)3 Account (io.nuls.account.entity.Account)2 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)2 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)2 Transaction (io.nuls.core.chain.entity.Transaction)2 Alias (io.nuls.account.entity.Alias)1 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 ConsensusAgentImpl (io.nuls.consensus.entity.ConsensusAgentImpl)1 ConsensusDepositImpl (io.nuls.consensus.entity.ConsensusDepositImpl)1 Agent (io.nuls.consensus.entity.member.Agent)1 Deposit (io.nuls.consensus.entity.member.Deposit)1 PocExitConsensusTransaction (io.nuls.consensus.entity.tx.PocExitConsensusTransaction)1 Result (io.nuls.core.chain.entity.Result)1 NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)1