本文整理汇总了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;
}
示例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 ();
}
示例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 ();
}
示例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 ();
}
};
}
示例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 ();
}
示例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;
}
示例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);
}