当前位置: 首页>>代码示例>>Java>>正文


Java ScriptChunk类代码示例

本文整理汇总了Java中org.bitcoinj.script.ScriptChunk的典型用法代码示例。如果您正苦于以下问题:Java ScriptChunk类的具体用法?Java ScriptChunk怎么用?Java ScriptChunk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScriptChunk类属于org.bitcoinj.script包,在下文中一共展示了ScriptChunk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildScript

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
public Script buildScript() {
	ScriptBuilder sbuilder = new ScriptBuilder();
	sbuilder = sbuilder.op(ScriptOpCodes.OP_RETURN);
	ScriptChunk protocolIdentifier = new ScriptChunk((byte) magicNumber.length, magicNumber);
	sbuilder = sbuilder.addChunk(protocolIdentifier);
	
	byte[] data;
	ByteBuffer result = ByteBuffer.allocate(8 + this.onionAddress.getBytes().length);
	result.put(this.onionAddress.getBytes());
	result.putInt(this.mixValue);
	result.putInt(this.acceptableLossValue);
	data = result.array();
	System.out.println("length of data arary " + data.length);
	
	ScriptChunk dataChunk = new ScriptChunk(data.length, data);
	sbuilder = sbuilder.addChunk(dataChunk);
	
	return sbuilder.build();
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:20,代码来源:BroadcastAnnouncement.java

示例2: isInputStandard

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
public static RuleViolation isInputStandard(TransactionInput input) {
    for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
        if (chunk.data != null && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
        if (chunk.isPushData()) {
            ECDSASignature signature;
            try {
                signature = ECKey.ECDSASignature.decodeFromDER(chunk.data);
            } catch (IllegalArgumentException x) {
                // Doesn't look like a signature.
                signature = null;
            }
            if (signature != null) {
                if (!TransactionSignature.isEncodingCanonical(chunk.data))
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
                if (!signature.isCanonical())
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
            }
        }
    }
    return RuleViolation.NONE;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:DefaultRiskAnalysis.java

示例3: isInputStandard

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
public static RuleViolation isInputStandard(TransactionInput input) {
    for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
        if (chunk.data != null && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
        if (chunk.isPushData()) {
            ECDSASignature signature;
            try {
                signature = ECKey.ECDSASignature.decodeFromDER(chunk.data);
            } catch (RuntimeException x) {
                // Doesn't look like a signature.
                signature = null;
            }
            if (signature != null) {
                if (!TransactionSignature.isEncodingCanonical(chunk.data))
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
                if (!signature.isCanonical())
                    return RuleViolation.SIGNATURE_CANONICAL_ENCODING;
            }
        }
    }
    return RuleViolation.NONE;
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:24,代码来源:DefaultRiskAnalysis.java

示例4: applyAndUpdate

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
public synchronized boolean applyAndUpdate(Transaction tx) {
    if (contains(tx.getHash().getBytes()))
        return true;
    boolean found = false;
    BloomUpdate flag = getUpdateFlag();
    for (TransactionOutput output : tx.getOutputs()) {
        Script script = output.getScriptPubKey();
        for (ScriptChunk chunk : script.getChunks()) {
            if (!chunk.isPushData())
                continue;
            if (contains(chunk.data)) {
                boolean isSendingToPubKeys = script.isSentToRawPubKey() || script.isSentToMultiSig();
                if (flag == BloomUpdate.UPDATE_ALL || (flag == BloomUpdate.UPDATE_P2PUBKEY_ONLY && isSendingToPubKeys))
                    insert(output.getOutPointFor().bitcoinSerialize());
                found = true;
            }
        }
    }
    return found;
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:21,代码来源:BloomFilter.java

示例5: scriptToString

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/**
 * Convert a script to a string format that suits the style expected in
 * tx_valid.json and tx_invalid.json.
 */
private static String scriptToString(Script scriptPubKey) {
    final StringBuilder buf = new StringBuilder();
    for (ScriptChunk chunk: scriptPubKey.getChunks()) {
        if (buf.length() > 0) {
            buf.append(" ");
        }
        if (chunk.isOpCode()) {
            buf.append(getOpCodeName(chunk.opcode));
        } else if (chunk.data != null) {
            // Data chunk
            buf.append("0x")
                .append(Integer.toString(chunk.opcode, 16)).append(" 0x")
                .append(Utils.HEX.encode(chunk.data));
        } else {
            buf.append(chunk.toString());
        }
    }
    return buf.toString();
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:24,代码来源:GenerateLowSTests.java

示例6: isOutputStandard

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/**
 * Checks the output to see if the script violates a standardness rule. Not complete.
 */
public static RuleViolation isOutputStandard(TransactionOutput output) {
    if (output.getValue().compareTo(MIN_ANALYSIS_NONDUST_OUTPUT) < 0)
        return RuleViolation.DUST;
    for (ScriptChunk chunk : output.getScriptPubKey().getChunks()) {
        if (chunk.isPushData() && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
    }
    return RuleViolation.NONE;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:13,代码来源:DefaultRiskAnalysis.java

示例7: testScript

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
public static boolean testScript (byte[] script, byte[] template, byte[]... parameters) {

        Script s = new Script(script);
        List<ScriptChunk> chunks = s.getChunks();

        int parameter = 0;

        for (int i = 0; i < chunks.size(); i++) {
            boolean correct = false;
            ScriptChunk chunk = chunks.get(i);
            byte templateChunk = template[i];

            int op = templateChunk;
            if (op < 0) {
                op = op + 256;
            }
            if (op == 255) {
                if (chunk.isPushData()) {
                    if (Arrays.equals(chunk.data, parameters[parameter])) {
                        parameter++;
                        correct = true;
                    }
                }
            } else {
                if (chunk.opcode == op) {
                    correct = true;
                }
            }
            if (!correct) {
                return false;
            }

        }

        return true;
    }
 
开发者ID:blockchain,项目名称:thunder,代码行数:37,代码来源:ScriptTools.java

示例8: isInputStandard

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
public static RuleViolation isInputStandard(TransactionInput input) {
    for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
        if (chunk.data != null && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
    }
    return RuleViolation.NONE;
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:9,代码来源:DefaultRiskAnalysis.java

示例9: getBloomFilter

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/**
 * <p>Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given
 * false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for
 * each key in the wallet, for the public key and the hash of the public key (address form).</p>
 * 
 * <p>This is used to generate a BloomFilter which can be {@link BloomFilter#merge(BloomFilter)}d with another.
 * It could also be used if you have a specific target for the filter's size.</p>
 * 
 * <p>See the docs for {@link BloomFilter(int, double)} for a brief explanation of anonymity when using bloom
 * filters.</p>
 */
@Override
public BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak) {
    // This is typically called by the PeerGroup, in which case it will have already explicitly taken the lock
    // before calling, but because this is public API we must still lock again regardless.
    lock.lock();
    keychainLock.lock();
    try {
        BloomFilter filter = keychain.getBloomFilter(size, falsePositiveRate, nTweak);

        for (Script script : watchedScripts) {
            for (ScriptChunk chunk : script.getChunks()) {
                // Only add long (at least 64 bit) data to the bloom filter.
                // If any long constants become popular in scripts, we will need logic
                // here to exclude them.
                if (!chunk.isOpCode() && chunk.data.length >= MINIMUM_BLOOM_DATA_LENGTH) {
                    filter.insert(chunk.data);
                }
            }
        }
        for (Transaction tx : getTransactions(false)) {
            for (int i = 0; i < tx.getOutputs().size(); i++) {
                TransactionOutput out = tx.getOutputs().get(i);
                try {
                    if (isTxOutputBloomFilterable(out)) {
                        TransactionOutPoint outPoint = new TransactionOutPoint(params, i, tx);
                        filter.insert(outPoint.bitcoinSerialize());
                    }
                } catch (ScriptException e) {
                    throw new RuntimeException(e); // If it is ours, we parsed the script correctly, so this shouldn't happen
                }
            }
        }
        return filter;
    } finally {
        keychainLock.unlock();
        lock.unlock();
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:50,代码来源:Wallet.java

示例10: nonShortestPossiblePushData

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
@Test
public void nonShortestPossiblePushData() {
    ScriptChunk nonStandardChunk = new ScriptChunk(OP_PUSHDATA1, new byte[75]);
    byte[] nonStandardScript = new ScriptBuilder().addChunk(nonStandardChunk).build().getProgram();
    // Test non-standard script as an input.
    Transaction tx = new Transaction(params);
    assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx));
    tx.addInput(new TransactionInput(params, null, nonStandardScript));
    assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
    // Test non-standard script as an output.
    tx.clearInputs();
    assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx));
    tx.addOutput(new TransactionOutput(params, null, COIN, nonStandardScript));
    assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:16,代码来源:DefaultRiskAnalysisTest.java

示例11: getOpName

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
public ScriptChunk getOpName() {
    switch(op) {
        case OP_NAME_FIRSTUPDATE:
        case OP_NAME_UPDATE:
            return args.get(0);
        
        default:
            throw new ScriptException("Not an AnyUpdate op");
    }
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:11,代码来源:NameScript.java

示例12: getOpValue

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
public ScriptChunk getOpValue() {
    switch(op) {
        case OP_NAME_FIRSTUPDATE:
            return args.get(2);
        
        case OP_NAME_UPDATE:
            return args.get(1);
        
        default:
            throw new ScriptException("Not an AnyUpdate op");
    }
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:13,代码来源:NameScript.java

示例13: isOutputStandard

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/**
 * Checks the output to see if the script violates a standardness rule. Not complete.
 */
public static RuleViolation isOutputStandard(TransactionOutput output) {
    if (MIN_ANALYSIS_NONDUST_OUTPUT.compareTo(output.getValue()) > 0)
        return RuleViolation.DUST;
    for (ScriptChunk chunk : output.getScriptPubKey().getChunks()) {
        if (chunk.isPushData() && !chunk.isShortestPossiblePushData())
            return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
    }
    return RuleViolation.NONE;
}
 
开发者ID:egordon,项目名称:CoinJoin,代码行数:13,代码来源:DefaultRiskAnalysis.java

示例14: getBloomFilter

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
/**
 * <p>Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given
 * false-positive rate if it has size elements. Keep in mind that you will get 2 elements in the bloom filter for
 * each key in the wallet, for the public key and the hash of the public key (address form).</p>
 * 
 * <p>This is used to generate a BloomFilter which can be {@link BloomFilter#merge(BloomFilter)}d with another.
 * It could also be used if you have a specific target for the filter's size.</p>
 * 
 * <p>See the docs for {@link BloomFilter(int, double)} for a brief explanation of anonymity when using bloom
 * filters.</p>
 */
@Override
public BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak) {
    // This is typically called by the PeerGroup, in which case it will have already explicitly taken the lock
    // before calling, but because this is public API we must still lock again regardless.
    lock.lock();
    try {
        BloomFilter filter = keychain.getBloomFilter(size, falsePositiveRate, nTweak);

        for (Script script : watchedScripts) {
            for (ScriptChunk chunk : script.getChunks()) {
                // Only add long (at least 64 bit) data to the bloom filter.
                // If any long constants become popular in scripts, we will need logic
                // here to exclude them.
                if (!chunk.isOpCode() && chunk.data.length >= MINIMUM_BLOOM_DATA_LENGTH) {
                    filter.insert(chunk.data);
                }
            }
        }
        for (Transaction tx : getTransactions(false)) {
            for (int i = 0; i < tx.getOutputs().size(); i++) {
                TransactionOutput out = tx.getOutputs().get(i);
                try {
                    if (isTxOutputBloomFilterable(out)) {
                        TransactionOutPoint outPoint = new TransactionOutPoint(params, i, tx);
                        filter.insert(outPoint.bitcoinSerialize());
                    }
                } catch (ScriptException e) {
                    throw new RuntimeException(e); // If it is ours, we parsed the script correctly, so this shouldn't happen
                }
            }
        }
        return filter;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:egordon,项目名称:CoinJoin,代码行数:48,代码来源:Wallet.java

示例15: transformTransaction

import org.bitcoinj.script.ScriptChunk; //导入依赖的package包/类
private String transformTransaction(String txInHex) throws BusinessException {
	byte[] txInBytes = DTOUtils.fromHex(txInHex);
	Transaction tx = new Transaction(appConfig.getNetworkParameters(), txInBytes);

	for (int i = 0; i < tx.getInputs().size(); i++) {
		List<ScriptChunk> chunks = tx.getInput(i).getScriptSig().getChunks();
		ScriptChunk relevantChunk = chunks.get(1);
		tx.getInput(i).setScriptSig(new ScriptBuilder().data(relevantChunk.data).build());
	}

	return DTOUtils.toHex(tx.bitcoinSerialize());
}
 
开发者ID:coinblesk,项目名称:coinblesk-server,代码行数:13,代码来源:AuthUserController.java


注:本文中的org.bitcoinj.script.ScriptChunk类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。