All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitcoinj.evolution.DeterministicMasternode Maven / Gradle / Ivy

The newest version!
package org.bitcoinj.evolution;

import org.bitcoinj.core.*;
import org.bitcoinj.crypto.BLSPublicKey;

import java.io.IOException;
import java.io.OutputStream;

public class DeterministicMasternode extends Masternode {

    public DeterministicMasternode(NetworkParameters params, byte [] payload, int cursor) {
        super(params, payload, cursor, params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT));
    }

    public DeterministicMasternode(DeterministicMasternode other) {
        super(other.params);
        proRegTxHash = other.proRegTxHash;
        collateralOutpoint = other.collateralOutpoint;
        operatorReward = other.operatorReward;
        state = new DeterministicMasternodeState(other.state);
    }

    TransactionOutPoint collateralOutpoint;
    short operatorReward;
    DeterministicMasternodeState state;

    @Override
    protected void parse() throws ProtocolException {
        proRegTxHash = readHash();
        collateralOutpoint = new TransactionOutPoint(params, payload, cursor);
        cursor += collateralOutpoint.getMessageSize();
        operatorReward = (short)readUint16();
        state = new DeterministicMasternodeState(params, payload, cursor);
        cursor += state.getMessageSize();
        length = cursor - offset;
    }

    @Override
    protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {
        stream.write(proRegTxHash.getReversedBytes());
        collateralOutpoint.bitcoinSerialize(stream);
        Utils.uint16ToByteStreamLE(operatorReward, stream);
        state.bitcoinSerializeToStream(stream);
    }

    public Sha256Hash getConfirmedHash() {
        return state.confirmedHash;
    }

    public MasternodeAddress getService() {
        return state.address;
    }

    public KeyId getKeyIdOwner() {
        return state.keyIDOwner;
    }

    public BLSPublicKey getPubKeyOperator() {
        return state.pubKeyOperator;
    }

    public KeyId getKeyIdVoting() {
        return state.keyIDVoting;
    }

    public boolean isValid() {
        return false;
    }

    public Sha256Hash getConfirmedHashWithProRegTxHash() {
        return state.confirmedHashWithProRegTxHash;
    }


    public String toString()
    {
        return String.format("DeterministicMN(proTxHash=%s, nCollateralIndex=%s, operatorReward=%f, state=%s",
                proRegTxHash, collateralOutpoint, (double)operatorReward / 100, state.toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy