Package org.bitcoinj.script

Examples of org.bitcoinj.script.Script


        // TODO: Support submitting multiple inputs in a single pledge tx here.
        TransactionInput input = pledge.addInput(stub);
        project.getOutputs().forEach(pledge::addOutput);
        ECKey key = input.getOutpoint().getConnectedKey(this);
        checkNotNull(key);
        Script script = stub.getScriptPubKey();
        if (aesKey != null)
            key = key.maybeDecrypt(aesKey);
        TransactionSignature signature = pledge.calculateSignature(0, key, script,
                Transaction.SigHash.ALL, true /* anyone can pay! */);
        if (script.isSentToAddress()) {
            input.setScriptSig(ScriptBuilder.createInputScript(signature, key));
        } else if (script.isSentToRawPubKey()) {
            // This branch will never be taken with the current design of the app because the only way to get money
            // in is via an address, but in future we might support direct-to-key payments via the payment protocol.
            input.setScriptSig(ScriptBuilder.createInputScript(signature));
        }
        input.setScriptSig(ScriptBuilder.createInputScript(signature,  key));
View Full Code Here


            // peer could have provided us with an OP_TRUE script or equivalent that would always pass here, even if
            // that's not the real script the tx was signed with. Forcing it to contain a CHECKSIG ensures that the
            // signature in the input is verified and that can't pass unless the scriptPubKey is as expected.
            // We also allow P2SH here because the input script must contain the correct output script in this case,
            // thus the provided output must match.
            final Script scriptPubKey = result.get(i).getScriptPubKey();
            if (isSafeToCrossCheck(scriptPubKey)) {
                TransactionInput input = tx.getInput(i);
                // Try to stop some idiot/troll from giving us a non-standard input, thus making us think we've raised
                // our funds but actually cannot easily claim the money.
                DefaultRiskAnalysis.RuleViolation violation = isInputStandard(input, scriptPubKey);
View Full Code Here

    // TODO: Move this into bitcoinj post-0.12
    private DefaultRiskAnalysis.RuleViolation isInputStandard(TransactionInput input, Script scriptPubKey) {
        DefaultRiskAnalysis.RuleViolation violation = input.isStandard();
        if (violation != DefaultRiskAnalysis.RuleViolation.NONE)
            return violation;
        Script scriptSig = input.getScriptSig();
        int args = getNumExpectedScriptSigArgs(scriptPubKey);
        LinkedList<byte[]> stack = Lists.newLinkedList();
        // This is fast and cannot execute any signature checks, because we already verified with the previous
        // isStandard() call that it only contains data pushes.
        Script.executeScript(null, -1, scriptSig, stack, true);
        if (scriptPubKey.isPayToScriptHash()) {
            Script redeemScript = null;
            try {
                if (stack.isEmpty())
                    throw new VerificationException("Empty stack");   // Should never happen: can't have empty scripts.
                redeemScript = new Script(stack.getLast());
                args += getNumExpectedScriptSigArgs(redeemScript);
            } catch (VerificationException e) {
                // We can get here if the redeem script is corrupted or unparseable in some way, or if the script type
                // simply isn't recognised by getNumExpected... - Bitcoin Core appears to simply treat any garbage
                // script as non-standard.
View Full Code Here

    private TxData makePledge(LHProtos.ProjectDetails.Builder details, double percentage) {
        TxData txData = new TxData();
        txData.pledge = new Transaction(params);
        long total = 0;
        for (LHProtos.Output output : details.getOutputsList()) {
            txData.pledge.addOutput(Coin.valueOf(output.getAmount()), new Script(output.getScript().toByteArray()));
            total += output.getAmount();
        }
        txData.key = new ECKey();
        final long pledgeSatoshis = (long) (total * percentage);
        txData.fakeStub = createFakeTx(params, Coin.valueOf(pledgeSatoshis), txData.key.toAddress(params));
View Full Code Here

    public void nonStandardInputP2SHOutput() throws Exception {
        // Unconsumed stack items are not allowed.
        TxData pledgeTX = makePledge(details, 0.1);
        TransactionInput input = pledgeTX.pledge.getInput(0);
        TransactionOutput origOutput = pledgeTX.fakeStub.getOutput(0);
        Script p2shPK = ScriptBuilder.createP2SHOutputScript(origOutput.getScriptPubKey());
        Script p2shSS = new ScriptBuilder(input.getScriptSig()).data(origOutput.getScriptBytes()).data(0, new byte[]{}).build();
        input.setScriptSig(p2shSS);
        pledgeTX.fakeStub.clearOutputs();
        pledgeTX.fakeStub.addOutput(origOutput.getValue(), p2shPK);
        LHProtos.Pledge.Builder pledge = pledgeToBuilder(pledgeTX, false);
        Project project = new Project(projectBuilder.build());
View Full Code Here

TOP

Related Classes of org.bitcoinj.script.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.