Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: andrewdb on March 13, 2016, 05:55:57 PM



Title: Lock funds in transaction A until transaction B?
Post by: andrewdb on March 13, 2016, 05:55:57 PM
I am learning about Bitcoin script, and wondering if something like the following is possible:

Is there a way to create a transaction which will lock funds until another transaction from someone else with a certain metadata exists?



Title: Re: Lock funds in transaction A until transaction B?
Post by: achow101 on March 13, 2016, 05:58:27 PM
I am learning about Bitcoin script, and wondering if something like the following is possible:

Is there a way to create a transaction which will lock funds until another transaction from someone else with a certain metadata exists?


You cannot lock them until a certain transaction exists. However, what you can do is have a script can only be spent from when a certain secret is known. That secret could be published in another transaction.

You can also lock to a certain date or block height.


Title: Re: Lock funds in transaction A until transaction B?
Post by: andrewdb on March 13, 2016, 06:07:36 PM
You cannot lock them until a certain transaction exists. However, what you can do is have a script can only be spent from when a certain secret is known. That secret could be published in another transaction.

Interesting.

Which opcodes are involved in this "lock-until-secret-published" strategy? Is this P2SH?

I'd love to learn more about this.


Title: Re: Lock funds in transaction A until transaction B?
Post by: achow101 on March 13, 2016, 06:24:12 PM
You cannot lock them until a certain transaction exists. However, what you can do is have a script can only be spent from when a certain secret is known. That secret could be published in another transaction.

Interesting.

Which opcodes are involved in this "lock-until-secret-published" strategy? Is this P2SH?

I'd love to learn more about this.
The address to lock the coins in is a p2sh address.

The script itself may look something like:
Code:
OP_SHA256 <sha256(secret)> OP_EQUALVERIFY
<pubkey> OP_CHECKSIG
This would mean that the person who is spending it must own the private key for the <pubkey> and must know the secret so that when the secret is put through the SHA256 hash, you get <sha256(secret)>.