Java Code Examples for org.bitcoinj.script.ScriptBuilder#createOpReturnScript()

The following examples show how to use org.bitcoinj.script.ScriptBuilder#createOpReturnScript() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WalletTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnOneOutputTest() throws Exception {
    // Tests basic send of transaction with one output that doesn't transfer any value but just writes OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(UNITTEST);
    Coin messagePrice = Coin.ZERO;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 2
Source File: WalletTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnMaxBytes() throws Exception {
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(UNITTEST);
    Script script = ScriptBuilder.createOpReturnScript(new byte[80]);
    tx.addOutput(Coin.ZERO, script);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 3
Source File: WalletTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnOneOutputWithValueTest() throws Exception {
    // Tests basic send of transaction with one output that destroys coins and has an OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(UNITTEST);
    Coin messagePrice = CENT;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    wallet.completeTx(request);
}
 
Example 4
Source File: WalletTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnTwoOutputsTest() throws Exception {
    // Tests sending transaction where one output transfers BTC, the other one writes OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(UNITTEST);
    Coin messagePrice = Coin.ZERO;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(CENT, OTHER_ADDRESS);
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    wallet.completeTx(request);
}
 
Example 5
Source File: WalletTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = Wallet.MultipleOpReturnRequested.class)
public void twoOpReturnsPerTransactionTest() throws Exception {
    // Tests sending transaction where there are 2 attempts to write OP_RETURN scripts - this should fail and throw MultipleOpReturnRequested.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(UNITTEST);
    Coin messagePrice = Coin.ZERO;
    Script script1 = ScriptBuilder.createOpReturnScript("hello world 1!".getBytes());
    Script script2 = ScriptBuilder.createOpReturnScript("hello world 2!".getBytes());
    tx.addOutput(messagePrice, script1);
    tx.addOutput(messagePrice, script2);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 6
Source File: WalletTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnOneOutputTest() throws Exception {
    // Tests basic send of transaction with one output that doesn't transfer any value but just writes OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = Coin.ZERO;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 7
Source File: WalletTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnMaxBytes() throws Exception {
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Script script = ScriptBuilder.createOpReturnScript(new byte[80]);
    tx.addOutput(Coin.ZERO, script);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 8
Source File: WalletTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnOneOutputWithValueTest() throws Exception {
    // Tests basic send of transaction with one output that destroys coins and has an OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = CENT;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    wallet.completeTx(request);
}
 
Example 9
Source File: WalletTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnTwoOutputsTest() throws Exception {
    // Tests sending transaction where one output transfers BTC, the other one writes OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = Coin.ZERO;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(CENT, OTHER_ADDRESS);
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    wallet.completeTx(request);
}
 
Example 10
Source File: WalletTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = Wallet.MultipleOpReturnRequested.class)
public void twoOpReturnsPerTransactionTest() throws Exception {
    // Tests sending transaction where there are 2 attempts to write OP_RETURN scripts - this should fail and throw MultipleOpReturnRequested.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = Coin.ZERO;
    Script script1 = ScriptBuilder.createOpReturnScript("hello world 1!".getBytes());
    Script script2 = ScriptBuilder.createOpReturnScript("hello world 2!".getBytes());
    tx.addOutput(messagePrice, script1);
    tx.addOutput(messagePrice, script2);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 11
Source File: OutputScript.java    From balzac with Apache License 2.0 5 votes vote down vote up
public static OutputScript createOP_RETURN(byte[] bytes) {
    return new OutputScript() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isP2SH() {
            return false;
        }

        @Override
        public boolean isP2PKH() {
            return false;
        }

        @Override
        public boolean isOP_RETURN() {
            return true;
        }

        @Override
        public Script getOutputScript() {
            return ScriptBuilder.createOpReturnScript(bytes);
        }

        @Override
        public Script build() {
            return getOutputScript();
        }
    };
}
 
Example 12
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnOneOutputTest() throws Exception {
    // Tests basic send of transaction with one output that doesn't transfer any value but just writes OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = Coin.ZERO;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 13
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnMaxBytes() throws Exception {
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Script script = ScriptBuilder.createOpReturnScript(new byte[80]);
    tx.addOutput(Coin.ZERO, script);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}
 
Example 14
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnOneOutputWithValueTest() throws Exception {
    // Tests basic send of transaction with one output that destroys coins and has an OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = CENT;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    wallet.completeTx(request);
}
 
Example 15
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void opReturnTwoOutputsTest() throws Exception {
    // Tests sending transaction where one output transfers BTC, the other one writes OP_RETURN.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = Coin.ZERO;
    Script script = ScriptBuilder.createOpReturnScript("hello world!".getBytes());
    tx.addOutput(CENT, OTHER_ADDRESS);
    tx.addOutput(messagePrice, script);
    SendRequest request = SendRequest.forTx(tx);
    wallet.completeTx(request);
}
 
Example 16
Source File: WalletTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Test(expected = Wallet.MultipleOpReturnRequested.class)
public void twoOpReturnsPerTransactionTest() throws Exception {
    // Tests sending transaction where there are 2 attempts to write OP_RETURN scripts - this should fail and throw MultipleOpReturnRequested.
    receiveATransaction(wallet, myAddress);
    Transaction tx = new Transaction(PARAMS);
    Coin messagePrice = Coin.ZERO;
    Script script1 = ScriptBuilder.createOpReturnScript("hello world 1!".getBytes());
    Script script2 = ScriptBuilder.createOpReturnScript("hello world 2!".getBytes());
    tx.addOutput(messagePrice, script1);
    tx.addOutput(messagePrice, script2);
    SendRequest request = SendRequest.forTx(tx);
    request.ensureMinRequiredFee = true;
    wallet.completeTx(request);
}