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


Java Script类代码示例

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


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

示例1: getWalletAddressOfReceived

import org.bitcoinj.script.Script; //导入依赖的package包/类
@Nullable
public static Address getWalletAddressOfReceived(final Transaction tx, final Wallet wallet) {
    for (final TransactionOutput output : tx.getOutputs()) {
        try {
            if (output.isMine(wallet)) {
                final Script script = output.getScriptPubKey();
                return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
            }
        } catch (final ScriptException x) {
            // swallow
        }
    }

    return null;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:16,代码来源:WalletUtils.java

示例2: calculateSigScript

import org.bitcoinj.script.Script; //导入依赖的package包/类
public Script calculateSigScript(Transaction tx, int inOffset, Wallet w) {
	assert(inOffset >= 0);
	//get key by pubkeyhash from wallet
	ECKey key = w.findKeyFromPubHash(this.pubkeyHash);
	assert(key != null);
	TransactionSignature ts = tx.calculateSignature(inOffset, key, redeemScript, SigHash.ALL, false);
	ScriptBuilder sb = new ScriptBuilder();
	byte[] sigEncoded = ts.encodeToBitcoin();
	sb.data(sigEncoded);
	assert(TransactionSignature.isEncodingCanonical(sigEncoded));
	sb.data(key.getPubKey());
	sb.data(redeemScript.getProgram());
	
	
	return sb.build();
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:17,代码来源:CLTVScriptPair.java

示例3: buildScript

import org.bitcoinj.script.Script; //导入依赖的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

示例4: maybeLookAheadScripts

import org.bitcoinj.script.Script; //导入依赖的package包/类
@Override
public void maybeLookAheadScripts() {
    super.maybeLookAheadScripts();
    int numLeafKeys = getLeafKeys().size();

    checkState(marriedKeysRedeemData.size() <= numLeafKeys, "Number of scripts is greater than number of leaf keys");
    if (marriedKeysRedeemData.size() == numLeafKeys)
        return;

    maybeLookAhead();
    for (DeterministicKey followedKey : getLeafKeys()) {
        RedeemData redeemData = getRedeemData(followedKey);
        Script scriptPubKey = ScriptBuilder.createP2SHOutputScript(redeemData.redeemScript);
        marriedKeysRedeemData.put(ByteString.copyFrom(scriptPubKey.getPubKeyHash()), redeemData);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:17,代码来源:MarriedKeyChain.java

示例5: addSignedInput

import org.bitcoinj.script.Script; //导入依赖的package包/类
/**
 * Adds a new and fully signed input for the given parameters. Note that this method is <b>not</b> thread safe
 * and requires external synchronization. Please refer to general documentation on Bitcoin scripting and contracts
 * to understand the values of sigHash and anyoneCanPay: otherwise you can use the other form of this method
 * that sets them to typical defaults.
 *
 * @throws ScriptException if the scriptPubKey is not a pay to address or pay to pubkey script.
 */
public TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scriptPubKey, ECKey sigKey,
                                       SigHash sigHash, boolean anyoneCanPay) throws ScriptException {
    // Verify the API user didn't try to do operations out of order.
    checkState(!outputs.isEmpty(), "Attempting to sign tx without outputs.");
    TransactionInput input = new TransactionInput(params, this, new byte[]{}, prevOut);
    addInput(input);
    Sha256Hash hash = hashForSignature(inputs.size() - 1, scriptPubKey, sigHash, anyoneCanPay);
    ECKey.ECDSASignature ecSig = sigKey.sign(hash);
    TransactionSignature txSig = new TransactionSignature(ecSig, sigHash, anyoneCanPay);
    if (scriptPubKey.isSentToRawPubKey())
        input.setScriptSig(ScriptBuilder.createInputScript(txSig));
    else if (scriptPubKey.isSentToAddress())
        input.setScriptSig(ScriptBuilder.createInputScript(txSig, sigKey));
    else
        throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Don't know how to sign for this kind of scriptPubKey: " + scriptPubKey);
    return input;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:26,代码来源:Transaction.java

示例6: assembleTransaction

import org.bitcoinj.script.Script; //导入依赖的package包/类
private void assembleTransaction() throws PaymentException {
    int numClientSigs = clientTxSignatures.size();
    int numServerSigs = serverTxSignatures.size();
    if (numClientSigs != numServerSigs) {
        throw new PaymentException(PaymentError.TRANSACTION_ERROR);
    }

    for (int i = 0; i < numClientSigs; ++i) {
        TransactionInput txIn = transaction.getInput(i);
        byte[] hash = txIn.getConnectedOutput().getScriptPubKey().getPubKeyHash();
        TimeLockedAddress tla = walletService.findTimeLockedAddressByHash(hash);
        Script scriptSig = tla.createScriptSigBeforeLockTime(
                clientTxSignatures.get(i), serverTxSignatures.get(i));
        txIn.setScriptSig(scriptSig);
        txIn.verify();
    }
    transaction.verify();
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:19,代码来源:PaymentFinalizeStep.java

示例7: addAddress

import org.bitcoinj.script.Script; //导入依赖的package包/类
private TimeLockedAddress addAddress(LockTime lockTime) {
    // Note: do not use in loop, adding to wallet is slow!
    TimeLockedAddress address = new TimeLockedAddress(
            multisigClientKey.getPubKey(),
            multisigServerKey.getPubKey(),
            lockTime.getLockTime());
    addresses.add(lockTime);
    addressHashes.put(
            Utils.HEX.encode(address.getAddressHash()),
            address);
    Script pubKeyScript = address.createPubkeyScript();
    pubKeyScript.setCreationTimeSeconds(lockTime.getTimeCreatedSeconds());
    wallet.addWatchedScripts(ImmutableList.of(pubKeyScript));
    Log.d(TAG, "Added address: " + address.toString(getNetworkParameters()));
    return address;
}
 
开发者ID:coinblesk,项目名称:coinblesk-client-gui,代码行数:17,代码来源:WalletService.java

示例8: addSignedInput

import org.bitcoinj.script.Script; //导入依赖的package包/类
/**
 * Adds a new and fully signed input for the given parameters. Note that this method is <b>not</b> thread safe
 * and requires external synchronization. Please refer to general documentation on Bitcoin scripting and contracts
 * to understand the values of sigHash and anyoneCanPay: otherwise you can use the other form of this method
 * that sets them to typical defaults.
 *
 * @throws ScriptException if the scriptPubKey is not a pay to address or pay to pubkey script.
 */
public TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scriptPubKey, ECKey sigKey,
                                       SigHash sigHash, boolean anyoneCanPay) throws ScriptException {
    // Verify the API user didn't try to do operations out of order.
    checkState(!outputs.isEmpty(), "Attempting to sign tx without outputs.");
    TransactionInput input = new TransactionInput(params, this, new byte[]{}, prevOut);
    addInput(input);
    Sha256Hash hash = hashForSignature(inputs.size() - 1, scriptPubKey, sigHash, anyoneCanPay);
    ECKey.ECDSASignature ecSig = sigKey.sign(hash);
    TransactionSignature txSig = new TransactionSignature(ecSig, sigHash, anyoneCanPay);
    if (scriptPubKey.isSentToRawPubKey())
        input.setScriptSig(ScriptBuilder.createInputScript(txSig));
    else if (scriptPubKey.isSentToAddress())
        input.setScriptSig(ScriptBuilder.createInputScript(txSig, sigKey));
    else
        throw new ScriptException("Don't know how to sign for this kind of scriptPubKey: " + scriptPubKey);
    return input;
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:26,代码来源:Transaction.java

示例9: isInputMine

import org.bitcoinj.script.Script; //导入依赖的package包/类
private boolean isInputMine(TransactionInput input) {
    lock.lock();
    try {
        try {
            Script script = input.getScriptSig();
            // TODO check multi sig scripts
            return isPubKeyMine(script.getPubKey());
        } catch (ScriptException e) {
            // We didn't understand this input ScriptSig: ignore it.
            log.debug("Could not parse tx input script: {}", e.toString());
            return false;
        }
    }
    finally {
        lock.unlock();
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:18,代码来源:TransactionWatcherWallet.java

示例10: testMultiSigOutputToString

import org.bitcoinj.script.Script; //导入依赖的package包/类
@Test
public void testMultiSigOutputToString() throws Exception {
    sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN);
    ECKey myKey = new ECKey();
    this.wallet.importKey(myKey);

    // Simulate another signatory
    ECKey otherKey = new ECKey();

    // Create multi-sig transaction
    Transaction multiSigTransaction = new Transaction(PARAMS);
    ImmutableList<ECKey> keys = ImmutableList.of(myKey, otherKey);

    Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys);
    multiSigTransaction.addOutput(Coin.COIN, scriptPubKey);

    SendRequest req = SendRequest.forTx(multiSigTransaction);
    this.wallet.completeTx(req);
    TransactionOutput multiSigTransactionOutput = multiSigTransaction.getOutput(0);

    assertThat(multiSigTransactionOutput.toString(), CoreMatchers.containsString("CHECKMULTISIG"));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:23,代码来源:TransactionOutputTest.java

示例11: for

import org.bitcoinj.script.Script; //导入依赖的package包/类
private static Transaction addPayments
        (Transaction transaction, ChannelStatus channelStatus, RevocationHash revocationHash, ECKey keyServer, ECKey keyClient) {
    Iterable<PaymentData> allPayments = new ArrayList<>(channelStatus.paymentList);

    for (PaymentData payment : allPayments) {
        Coin value = Coin.valueOf(payment.amount);
        Script script;
        if (payment.sending) {
            script = ScriptTools.getChannelTxOutputPaymentSending(keyServer, keyClient, revocationHash, payment.secret, payment.timestampRefund);
        } else {
            script = ScriptTools.getChannelTxOutputPaymentReceiving(keyServer, keyClient, revocationHash, payment.secret, payment.timestampRefund);
        }
        transaction.addOutput(value, script);
    }
    return transaction;
}
 
开发者ID:blockchain,项目名称:thunder,代码行数:17,代码来源:LNPaymentLogicImpl.java

示例12: getOutputAddress

import org.bitcoinj.script.Script; //导入依赖的package包/类
static Address getOutputAddress(TransactionOutput out) {
    try {
        Script script = out.getScriptPubKey();
        if (script.isSentToAddress() || script.isPayToScriptHash()) {
            return script.getToAddress(Constants.NETWORK_PARAMS);
        }
    } catch (ScriptException e) {
        // TODO
        //LOG.error("Error while reading transaction output address", e);
    }
    return null;
}
 
开发者ID:eztam-,项目名称:bitcoin-bruteforce,代码行数:13,代码来源:TransactionProcessor.java

示例13: getToAddressOfSent

import org.bitcoinj.script.Script; //导入依赖的package包/类
@Nullable
public static Address getToAddressOfSent(final Transaction tx, final Wallet wallet) {
    for (final TransactionOutput output : tx.getOutputs()) {
        try {
            if (!output.isMine(wallet)) {
                final Script script = output.getScriptPubKey();
                return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
            }
        } catch (final ScriptException x) {
            // swallow
        }
    }

    return null;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:16,代码来源:WalletUtils.java

示例14: sendBroadcastAnnouncement

import org.bitcoinj.script.Script; //导入依赖的package包/类
public void sendBroadcastAnnouncement(BroadcastAnnouncement ba, File f, ProofMessage pm, int lockTime) throws InsufficientMoneyException {
	//build transaction
	Transaction tx = new Transaction(params);
	
	Script s = ba.buildScript();
	System.out.println("Script size is " + s.SIG_SIZE);
	//System.out.println(s.getScriptType());
	ECKey psnymKey = new ECKey();
	long unixTime = System.currentTimeMillis() / 1000L;
	//TODO use bitcoin nets median time
	tx.setLockTime(CLTVScriptPair.currentBitcoinBIP113Time(bc)-1);
	CLTVScriptPair sp = new CLTVScriptPair(psnymKey, CLTVScriptPair.currentBitcoinBIP113Time(bc)+lockTime);
	w.importKey(psnymKey);
	tx.addOutput(new TransactionOutput(params, tx, pm.getLastTransactionOutput().getValue().subtract(estimateBroadcastFee()), sp.getPubKeyScript().getProgram()));
	tx.addOutput(Coin.ZERO, s);
	tx.addInput(pm.getLastTransactionOutput());
	tx.getInput(0).setSequenceNumber(3); //the concrete value doesn't matter, this is just for cltv
	tx.getInput(0).setScriptSig(pm.getScriptPair().calculateSigScript(tx, 0, w));
	
	try {
		w.commitTx(tx);
		w.saveToFile(f);
	} catch (IOException e1) {
		e1.printStackTrace();
	}
	
	TransactionBroadcast broadcast = pg.broadcastTransaction(tx);
	pm.addTransaction(tx, 0, sp);
	pm.writeToFile();
	System.out.println("save broadcast announcement to file");
	
	

}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:35,代码来源:TransactionGenerator.java

示例15: readObject

import org.bitcoinj.script.Script; //导入依赖的package包/类
private void readObject(ObjectInputStream ois)
		throws ClassNotFoundException, IOException {
	this.redeemScript = new Script((byte[]) ois.readObject());
	this.pubKeyScript = new Script((byte[]) ois.readObject());
	this.pubkeyHash = (byte[]) ois.readObject();	
	this.pubkey = (byte[]) ois.readObject();
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:8,代码来源:CLTVScriptPair.java


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