Search in sources :

Example 1 with MultiSigType

use of co.rsk.bitcoinj.script.RedeemScriptParser.MultiSigType in project rskj by rsksmart.

the class BridgeUtils method countMissingSignatures.

/**
 * Return the amount of missing signatures for a tx.
 * @param btcContext Btc context
 * @param btcTx The btc tx to check
 * @return 0 if was signed by the required number of federators, amount of missing signatures otherwise
 */
public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) {
    // Check missing signatures for only one input as it is not
    // possible for a federator to leave unsigned inputs in a tx
    Context.propagate(btcContext);
    int unsigned = 0;
    TransactionInput input = btcTx.getInput(0);
    Script scriptSig = input.getScriptSig();
    List<ScriptChunk> chunks = scriptSig.getChunks();
    Script redeemScript = new Script(chunks.get(chunks.size() - 1).data);
    RedeemScriptParser parser = RedeemScriptParserFactory.get(redeemScript.getChunks());
    MultiSigType multiSigType;
    int lastChunk;
    multiSigType = parser.getMultiSigType();
    if (multiSigType == MultiSigType.STANDARD_MULTISIG || multiSigType == MultiSigType.FAST_BRIDGE_MULTISIG) {
        lastChunk = chunks.size() - 1;
    } else {
        lastChunk = chunks.size() - 2;
    }
    for (int i = 1; i < lastChunk; i++) {
        ScriptChunk chunk = chunks.get(i);
        if (!chunk.isOpCode() && chunk.data.length == 0) {
            unsigned++;
        }
    }
    return unsigned;
}
Also used : Script(co.rsk.bitcoinj.script.Script) MultiSigType(co.rsk.bitcoinj.script.RedeemScriptParser.MultiSigType) ScriptChunk(co.rsk.bitcoinj.script.ScriptChunk) RedeemScriptParser(co.rsk.bitcoinj.script.RedeemScriptParser)

Example 2 with MultiSigType

use of co.rsk.bitcoinj.script.RedeemScriptParser.MultiSigType in project rskj by rsksmart.

the class BridgeUtils method hasEnoughSignatures.

/**
 * Checks whether a btc tx has been signed by the required number of federators.
 * @param btcContext Btc context
 * @param btcTx The btc tx to check
 * @return True if was signed by the required number of federators, false otherwise
 */
public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) {
    // When the tx is constructed OP_0 are placed where signature should go.
    // Check all OP_0 have been replaced with actual signatures in all inputs
    Context.propagate(btcContext);
    Script scriptSig;
    List<ScriptChunk> chunks;
    Script redeemScript;
    RedeemScriptParser parser;
    MultiSigType multiSigType;
    int lastChunk;
    for (TransactionInput input : btcTx.getInputs()) {
        scriptSig = input.getScriptSig();
        chunks = scriptSig.getChunks();
        redeemScript = new Script(chunks.get(chunks.size() - 1).data);
        parser = RedeemScriptParserFactory.get(redeemScript.getChunks());
        multiSigType = parser.getMultiSigType();
        if (multiSigType == MultiSigType.STANDARD_MULTISIG || multiSigType == MultiSigType.FAST_BRIDGE_MULTISIG) {
            lastChunk = chunks.size() - 1;
        } else {
            lastChunk = chunks.size() - 2;
        }
        for (int i = 1; i < lastChunk; i++) {
            ScriptChunk chunk = chunks.get(i);
            if (!chunk.isOpCode() && chunk.data.length == 0) {
                return false;
            }
        }
    }
    return true;
}
Also used : Script(co.rsk.bitcoinj.script.Script) MultiSigType(co.rsk.bitcoinj.script.RedeemScriptParser.MultiSigType) ScriptChunk(co.rsk.bitcoinj.script.ScriptChunk) RedeemScriptParser(co.rsk.bitcoinj.script.RedeemScriptParser)

Aggregations

RedeemScriptParser (co.rsk.bitcoinj.script.RedeemScriptParser)2 MultiSigType (co.rsk.bitcoinj.script.RedeemScriptParser.MultiSigType)2 Script (co.rsk.bitcoinj.script.Script)2 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)2