How can you build transaction with custom output/input scripts ?

+4 votes
Hi,

I was wondering how/if we can build custom scripts into transactions outputs, like "OP_HASH160 myHash OP_EQUAL" instead of the basic "OP_DUP OP_HASH160 pubKeyHash OP_EQUALVERIFY OP_CHECKSIG" for example ? Is it possible with createrawtransaction ?

Thanks :)
asked Jul 26, 2017 by GCath

1 Answer

+2 votes

In order to do this you would need to build the transactions manually, not via createrawtransaction or createrawsendfrom. Any transaction building library which is compatible with bitcoin can easily be used with MultiChain, because the transaction formats (including script codes) are identical. Note however that the multichain protocol adds various rules regarding transaction inputs and outputs that are not in the bitcoin protocol, so you might also have to take a look at the MultiChain source code to see what needs to be changed. The AcceptMultiChainTransaction() function is a good place to start.

answered Jul 26, 2017 by MultiChain
Alright thanks I'll look into that !
Alright, I managed to create a simple transaction with only an OP_TRUE as output script.
What I do is create the transaction with createrawtransaction then change the output script of it manually (in the hex data) before signing it. It works perfectly on bitcoin testnet: https://www.blocktrail.com/tBTC/tx/09fec92d95335ed650012fe44241d13ab56753881c3155d839f7d60e1230007a

Unfortunately, when I try to do the same with Multichain, I can manage to create, sign and send the transaction easily. I then see it IN the rawmempool and it works perfectly until the daemon tries to create a new Block.

At this point, I get this error on the daemon:
wtxs: AddTx  Error: 11
ERROR: ConnectTip() : ConnectBlock 00000012620e4f87ffea2aa006e7eab5026b9bf31adeb14f3a104d30a0596caf failed, Wtxs AddTx 784f7d6d9655a1c9bdc88d81570d85f41b62307a9a0230411c6384a5081d79bd, error: 11

Shortly after that, the daemon gives a core dump:
MultiChainMiner: Block Found - 00000033b8d64968cde1d90849fa17bd55d39d2701cbcf1e3f0c2c2b836776cb, prev: 000000d6797e6d1cc60d7618ca34f8521abe43a58d9c9519cfa452e9839351ec, height: 37, txs: 1
  nActualTimespan = 10  before bounds
GetNextWorkRequired RETARGET
Params().TargetTimespan() = 240    nActualTimespan = 60
Before: 1e00ffff  000000ffff000000000000000000000000000000000000000000000000000000
After:  1d3fffc0  0000003fffc00000000000000000000000000000000000000000000000000000
multichaind: core/main.cpp:2222: bool ConnectBlock(const CBlock&, CValidationState&, CBlockIndex*, CCoinsViewCache&, bool): Assertion `hashPrevBlock == view.GetBestBlock()' failed.
Abandon (core dumped)

After this, the daemon crashes if you try to restart it. As there is no error during sendrawtransaction, I don't get why the daemon is crashing. Any idea where the issue comes from ?

Sorry for the long post !
Thanks - this looks like a bug and we'll look into it.
Thank you for reporting this. We've identified the source of this bug. This happens sometimes for non-standard outputs under very specific and unusual blockchain parameters.

We will fix this bug in the next release (1.0.1). Meanwhile you can start multichaind with -walletdbversion=1 to avoid this issue. If you have to repair existing chain you can do it with -walletdbversion=1 -reindex=1.

When upgrading to 1.0.1 with the fix, you will be able to switch back to default  walletdbversion using "-walletdbversion=2 -reindex=1".
Thank you for your answer Michael, I've just tried running the blockchain with those parameters, send another "OP_TRUE" transaction then redeem it and it works perfectly !
...