mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 02:05:53 +00:00
Add an OP_RETURN convenience method on ScriptBuilder and convert unit tests to use it.
This commit is contained in:
parent
f65da9c201
commit
199a741850
@ -331,4 +331,14 @@ public class ScriptBuilder {
|
|||||||
Collections.sort(pubkeys, ECKey.PUBKEY_COMPARATOR);
|
Collections.sort(pubkeys, ECKey.PUBKEY_COMPARATOR);
|
||||||
return ScriptBuilder.createMultiSigOutputScript(threshold, pubkeys);
|
return ScriptBuilder.createMultiSigOutputScript(threshold, pubkeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a script of the form OP_RETURN [data]. This feature allows you to attach a small piece of data (like
|
||||||
|
* a hash of something stored elsewhere) to a zero valued output which can never be spent and thus does not pollute
|
||||||
|
* the ledger.
|
||||||
|
*/
|
||||||
|
public static Script createOpReturnScript(byte[] data) {
|
||||||
|
checkArgument(data.length <= 40);
|
||||||
|
return new ScriptBuilder().op(OP_RETURN).data(data).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1650,7 +1650,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
receiveATransaction(wallet, myAddress);
|
receiveATransaction(wallet, myAddress);
|
||||||
Transaction tx = new Transaction(params);
|
Transaction tx = new Transaction(params);
|
||||||
Coin messagePrice = Coin.ZERO;
|
Coin messagePrice = Coin.ZERO;
|
||||||
Script script = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world!".getBytes()).build();
|
Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
|
||||||
tx.addOutput(messagePrice, script);
|
tx.addOutput(messagePrice, script);
|
||||||
SendRequest request = Wallet.SendRequest.forTx(tx);
|
SendRequest request = Wallet.SendRequest.forTx(tx);
|
||||||
wallet.completeTx(request);
|
wallet.completeTx(request);
|
||||||
@ -1662,7 +1662,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
receiveATransaction(wallet, myAddress);
|
receiveATransaction(wallet, myAddress);
|
||||||
Transaction tx = new Transaction(params);
|
Transaction tx = new Transaction(params);
|
||||||
Coin messagePrice = CENT;
|
Coin messagePrice = CENT;
|
||||||
Script script = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world!".getBytes()).build();
|
Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
|
||||||
tx.addOutput(messagePrice, script);
|
tx.addOutput(messagePrice, script);
|
||||||
SendRequest request = Wallet.SendRequest.forTx(tx);
|
SendRequest request = Wallet.SendRequest.forTx(tx);
|
||||||
wallet.completeTx(request);
|
wallet.completeTx(request);
|
||||||
@ -1675,7 +1675,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
Address notMyAddr = new ECKey().toAddress(params);
|
Address notMyAddr = new ECKey().toAddress(params);
|
||||||
Transaction tx = new Transaction(params);
|
Transaction tx = new Transaction(params);
|
||||||
Coin messagePrice = Coin.ZERO;
|
Coin messagePrice = Coin.ZERO;
|
||||||
Script script = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world!".getBytes()).build();
|
Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
|
||||||
tx.addOutput(CENT, notMyAddr);
|
tx.addOutput(CENT, notMyAddr);
|
||||||
tx.addOutput(messagePrice, script);
|
tx.addOutput(messagePrice, script);
|
||||||
SendRequest request = Wallet.SendRequest.forTx(tx);
|
SendRequest request = Wallet.SendRequest.forTx(tx);
|
||||||
@ -1688,8 +1688,8 @@ public class WalletTest extends TestWithWallet {
|
|||||||
receiveATransaction(wallet, myAddress);
|
receiveATransaction(wallet, myAddress);
|
||||||
Transaction tx = new Transaction(params);
|
Transaction tx = new Transaction(params);
|
||||||
Coin messagePrice = Coin.ZERO;
|
Coin messagePrice = Coin.ZERO;
|
||||||
Script script1 = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world 1!".getBytes()).build();
|
Script script1 = ScriptBuilder.createOpReturnScript("hello world 1!".getBytes());
|
||||||
Script script2 = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world 2!".getBytes()).build();
|
Script script2 = ScriptBuilder.createOpReturnScript("hello world 2!".getBytes());
|
||||||
tx.addOutput(messagePrice, script1);
|
tx.addOutput(messagePrice, script1);
|
||||||
tx.addOutput(messagePrice, script2);
|
tx.addOutput(messagePrice, script2);
|
||||||
SendRequest request = Wallet.SendRequest.forTx(tx);
|
SendRequest request = Wallet.SendRequest.forTx(tx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user