當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptFormat類代碼示例

本文整理匯總了Java中com.bitsofproof.supernode.common.ScriptFormat的典型用法代碼示例。如果您正苦於以下問題:Java ScriptFormat類的具體用法?Java ScriptFormat怎麽用?Java ScriptFormat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScriptFormat類屬於com.bitsofproof.supernode.common包,在下文中一共展示了ScriptFormat類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createCoinbase

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
/**
 * create a coin base transaction crediting the given address with a value and block height This is used in automated tests only.
 */
public static Transaction createCoinbase (Address address, long value, int blockHeight) throws ValidationException
{
	Transaction cb = new Transaction ();

	cb.setInputs (new ArrayList<TransactionInput> ());
	cb.setOutputs (new ArrayList<TransactionOutput> ());

	TransactionOutput out = new TransactionOutput ();
	out.setValue (value);
	cb.getOutputs ().add (out);

	out.setScript (address.getAddressScript ());

	TransactionInput in = new TransactionInput ();
	in.setSourceHash (Hash.ZERO_HASH_STRING);
	in.setIx (0);
	cb.getInputs ().add (in);

	ScriptFormat.Writer writer = new ScriptFormat.Writer ();
	writer.writeInt32 (blockHeight);
	in.setScript (writer.toByteArray ());

	cb.computeHash ();
	return cb;
}
 
開發者ID:bitsofproof,項目名稱:bop-bitcoin-client,代碼行數:29,代碼來源:Transaction.java

示例2: getAddressScript

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
/**
 * get the transaction output script suitable to refer to this address
 * 
 * @return transaction output script
 * @throws ValidationException
 *             - if output script is unknown for this address
 */
public byte[] getAddressScript () throws ValidationException
{
	ScriptFormat.Writer writer = new ScriptFormat.Writer ();
	if ( type == Address.Type.COMMON )
	{
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_DUP));
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_HASH160));
		writer.writeData (bytes);
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_EQUALVERIFY));
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_CHECKSIG));
	}
	else if ( type == Address.Type.P2SH )
	{
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_HASH160));
		writer.writeData (bytes);
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_EQUAL));
	}
	else
	{
		throw new ValidationException ("unknown sink address type");
	}
	return writer.toByteArray ();
}
 
開發者ID:bitsofproof,項目名稱:bop-bitcoin-client,代碼行數:31,代碼來源:Address.java

示例3: getAddressScript

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
public byte[] getAddressScript () throws ValidationException
{
	ScriptFormat.Writer writer = new ScriptFormat.Writer ();
	if ( type == Address.Type.COMMON )
	{
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_DUP));
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_HASH160));
		writer.writeData (bytes);
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_EQUALVERIFY));
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_CHECKSIG));
	}
	else if ( type == Address.Type.P2SH )
	{
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_HASH160));
		writer.writeData (bytes);
		writer.writeToken (new ScriptFormat.Token (Opcode.OP_EQUAL));
	}
	else
	{
		throw new ValidationException ("unknown sink address type");
	}
	return writer.toByteArray ();
}
 
開發者ID:greenaddress,項目名稱:WalletCordova,代碼行數:24,代碼來源:Address.java

示例4: createTransactionSource

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
@Override
protected TransactionSource createTransactionSource (TransactionOutput output)
{
	return new TransactionSource (output, this)
	{
		@Override
		protected byte[] spend (int ix, Transaction transaction) throws ValidationException
		{
			ScriptFormat.Writer sw = new ScriptFormat.Writer ();
			sw.writeData (new byte[0]);
			for ( int i = 0; i < publicKeys.size (); ++i )
			{
				sw.writeData (new byte[0]);
			}
			sw.writeData (getVaultScript ());
			return sw.toByteArray ();
		}
	};
}
 
開發者ID:bitsofproof,項目名稱:btc1k,代碼行數:20,代碼來源:Vault.java

示例5: getVaultScript

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
private byte[] getVaultScript () throws ValidationException
{
	ScriptFormat.Writer writer = new ScriptFormat.Writer ();
	writer.writeToken (new ScriptFormat.Token (ScriptFormat.Opcode.OP_2));
	for ( Key key : publicKeys.values () )
	{
		writer.writeData (key.getPublic ());
	}
	writer.writeToken (new ScriptFormat.Token (ScriptFormat.Opcode.OP_3));
	writer.writeToken (new ScriptFormat.Token (ScriptFormat.Opcode.OP_CHECKMULTISIG));
	return writer.toByteArray ();
}
 
開發者ID:bitsofproof,項目名稱:btc1k,代碼行數:13,代碼來源:Vault.java

示例6: getSignedBy

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
List<String> getSignedBy (Transaction transaction) throws ValidationException
{
	List<String> names = new ArrayList<> ();
	for ( TransactionInput input : transaction.getInputs () )
	{
		List<Token> tokens = ScriptFormat.parse (input.getScript ());
		Iterator<Map.Entry<String, ECPublicKey>> it = publicKeys.entrySet ().iterator ();
		for ( int i = 1; i < tokens.size () - 1; ++i )
		{
			if ( tokens.get (i).data != null )
			{
				Map.Entry<String, ECPublicKey> e = it.next ();
				String name = e.getKey ();
				Key k = e.getValue ();
				if ( tokens.get (i).op != ScriptFormat.Opcode.OP_FALSE )
				{
					byte[] digest = transaction.hashTransaction (0, ScriptFormat.SIGHASH_ALL, getVaultScript ());
					if ( k.verify (digest, tokens.get (i).data) )
					{
						names.add (name);
					}
				}
			}
		}
		break;
	}
	return names;
}
 
開發者ID:bitsofproof,項目名稱:btc1k,代碼行數:29,代碼來源:Vault.java

示例7: getOutputAddress

import com.bitsofproof.supernode.common.ScriptFormat; //導入依賴的package包/類
/**
 * Get the address referenced in the script. The parse might fail for not plain-vanilla transactions and return null
 */
public Address getOutputAddress ()
{
	return ScriptFormat.getAddress (script);
}
 
開發者ID:bitsofproof,項目名稱:bop-bitcoin-client,代碼行數:8,代碼來源:TransactionOutput.java


注:本文中的com.bitsofproof.supernode.common.ScriptFormat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。