Search in sources :

Example 6 with Address

use of io.nuls.account.entity.Address in project nuls by nuls-io.

the class ConsensusMeetingRunner method yellowPunishTx.

private void yellowPunishTx(Block bestBlock, List<Transaction> txList, PocMeetingMember self) throws NulsException, IOException {
    BlockRoundData lastBlockRoundData = new BlockRoundData();
    try {
        lastBlockRoundData.parse(bestBlock.getHeader().getExtend());
    } catch (NulsException e) {
        Log.error(e);
    }
    // continuous blocks in the same round
    boolean ok = (self.getRoundIndex() == lastBlockRoundData.getRoundIndex()) && (self.getIndexOfRound() == (1 + lastBlockRoundData.getPackingIndexOfRound()));
    // continuous blocks between two rounds
    ok = ok || (self.getRoundIndex() == (lastBlockRoundData.getRoundIndex() + 1) && self.getIndexOfRound() == 1 && lastBlockRoundData.getPackingIndexOfRound() == lastBlockRoundData.getConsensusMemberCount());
    // two rounds
    ok = ok || (self.getRoundIndex() - 1) > lastBlockRoundData.getRoundIndex();
    if (ok) {
        return;
    }
    List<Address> addressList = new ArrayList<>();
    PocMeetingRound round = consensusManager.getCurrentRound();
    long roundIndex = lastBlockRoundData.getRoundIndex();
    int packingIndex = 0;
    if (lastBlockRoundData.getPackingIndexOfRound() == lastBlockRoundData.getConsensusMemberCount()) {
        packingIndex = 1;
    } else {
        packingIndex = lastBlockRoundData.getPackingIndexOfRound() + 1;
    }
    while (true) {
        PocMeetingRound tempRound;
        if (roundIndex == self.getRoundIndex()) {
            tempRound = round;
        } else if (roundIndex == (self.getRoundIndex() - 1)) {
            tempRound = round.getPreviousRound();
        } else {
            break;
        }
        if (tempRound.getIndex() > round.getIndex()) {
            break;
        }
        if (tempRound.getIndex() == round.getIndex() && packingIndex >= self.getIndexOfRound()) {
            break;
        }
        if (packingIndex >= tempRound.getMemberCount()) {
            roundIndex++;
            packingIndex = 1;
            continue;
        }
        PocMeetingMember member;
        try {
            member = tempRound.getMember(packingIndex);
            if (null == member) {
                break;
            }
        } catch (Exception e) {
            break;
        }
        packingIndex++;
        addressList.add(Address.fromHashs(member.getAgentAddress()));
    }
    if (addressList.isEmpty()) {
        return;
    }
    YellowPunishTransaction punishTx = new YellowPunishTransaction();
    YellowPunishData data = new YellowPunishData();
    data.setAddressList(addressList);
    data.setHeight(bestBlock.getHeader().getHeight() + 1);
    punishTx.setTxData(data);
    punishTx.setTime(TimeService.currentTimeMillis());
    punishTx.setFee(Na.ZERO);
    punishTx.setHash(NulsDigestData.calcDigestData(punishTx));
    punishTx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(punishTx.getHash(), consensusManager.getConsensusStatusInfo().getAccount(), NulsContext.CACHED_PASSWORD_OF_WALLET).serialize());
    txList.add(punishTx);
}
Also used : Address(io.nuls.account.entity.Address) YellowPunishTransaction(io.nuls.consensus.entity.tx.YellowPunishTransaction) YellowPunishData(io.nuls.consensus.entity.YellowPunishData) PocMeetingRound(io.nuls.consensus.entity.meeting.PocMeetingRound) PocMeetingMember(io.nuls.consensus.entity.meeting.PocMeetingMember) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsException(io.nuls.core.exception.NulsException) BlockRoundData(io.nuls.consensus.entity.block.BlockRoundData)

Example 7 with Address

use of io.nuls.account.entity.Address in project nuls by nuls-io.

the class AliasValidator method validate.

@Override
public ValidateResult validate(AliasTransaction tx) {
    Alias alias = tx.getTxData();
    if (StringUtils.isBlank(alias.getAddress()) || new Address(alias.getAddress()).getHash().length != 23) {
        return ValidateResult.getFailedResult("The address format error");
    }
    if (!StringUtils.validAlias(alias.getAlias())) {
        return ValidateResult.getFailedResult("The alias is between 3 to 20 characters");
    }
    AliasPo aliasPo = getAliasDataService().get(alias.getAlias());
    if (aliasPo != null) {
        return ValidateResult.getFailedResult("The alias has been occupied");
    }
    return ValidateResult.getSuccessResult();
}
Also used : Address(io.nuls.account.entity.Address) Alias(io.nuls.account.entity.Alias) AliasPo(io.nuls.db.entity.AliasPo)

Example 8 with Address

use of io.nuls.account.entity.Address in project nuls by nuls-io.

the class AccountResource method getAddress.

@GET
@Path("/address")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getAddress(@QueryParam("publicKey") String publicKey, @QueryParam("subChainId") Integer subChainId) {
    Address address = new Address((short) subChainId.intValue(), Hex.decode(publicKey));
    RpcResult result = RpcResult.getSuccess();
    result.setData(address.toString());
    return result;
}
Also used : Address(io.nuls.account.entity.Address)

Example 9 with Address

use of io.nuls.account.entity.Address in project nuls by nuls-io.

the class YellowPunishData method serializeToStream.

@Override
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException {
    stream.writeVarInt(height);
    stream.writeVarInt(addressList.size());
    for (Address address : addressList) {
        stream.write(address.getHash());
    }
}
Also used : Address(io.nuls.account.entity.Address)

Aggregations

Address (io.nuls.account.entity.Address)9 NulsException (io.nuls.core.exception.NulsException)3 Account (io.nuls.account.entity.Account)2 YellowPunishData (io.nuls.consensus.entity.YellowPunishData)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 P2PKHScript (io.nuls.core.script.P2PKHScript)2 Alias (io.nuls.account.entity.Alias)1 BlockRoundData (io.nuls.consensus.entity.block.BlockRoundData)1 PocMeetingMember (io.nuls.consensus.entity.meeting.PocMeetingMember)1 PocMeetingRound (io.nuls.consensus.entity.meeting.PocMeetingRound)1 YellowPunishTransaction (io.nuls.consensus.entity.tx.YellowPunishTransaction)1 Na (io.nuls.core.chain.entity.Na)1 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)1 ECKey (io.nuls.core.crypto.ECKey)1 AliasPo (io.nuls.db.entity.AliasPo)1 PunishLogPo (io.nuls.db.entity.PunishLogPo)1 Coin (io.nuls.ledger.entity.params.Coin)1 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)1 UnlockNulsTransaction (io.nuls.ledger.entity.tx.UnlockNulsTransaction)1 IOException (java.io.IOException)1