Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: pianist on November 04, 2015, 11:46:00 AM



Title: OP_XXX: How to take current block height?
Post by: pianist on November 04, 2015, 11:46:00 AM
I want to make conditional output script, something like this:

Code:
IF (current_block_height < 400000)
{
   check_multisig(2,3);
}
ELSE
{
   usual OP_CHECKSIG condition;
}

There are many OP_XXX instructions, but there is no way to get current height of blockchain, or height of block where output script is stored.

May be there is easy way to get such data? :)


Title: Re: OP_XXX: How to take current block height?
Post by: belcher on November 04, 2015, 03:16:44 PM
You need to wait for OP_CHECKLOCKTIMEVERIFY

https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki#escrow


Title: Re: OP_XXX: How to take current block height?
Post by: pianist on November 04, 2015, 05:45:31 PM
wait for OP_CHECKLOCKTIMEVERIFY

Are there any plans to implement this OP in near future?

I justed greped sources and there is no such string in sources... :(


Title: Re: OP_XXX: How to take current block height?
Post by: domob on November 04, 2015, 05:53:27 PM
wait for OP_CHECKLOCKTIMEVERIFY

Are there any plans to implement this OP in near future?

I justed greped sources and there is no such string in sources... :(


It is already in the current development sources, and it will "activate" on the live network as soon as 75%/95% of hashing power have upgraded.  I guess that will be once 0.12 is released.


Title: Re: OP_XXX: How to take current block height?
Post by: gmaxwell on November 05, 2015, 02:45:52 AM
I guess that will be once 0.12 is released.
Soft-forks shouldn't be and aren't tied to Bitcoin core major versions.  There will be 0.11.2 and 0.10. releases out with this in the next week or so.


Title: Re: OP_XXX: How to take current block height?
Post by: pianist on November 05, 2015, 06:13:37 PM
There will be 0.11.2 and 0.10. releases out with this in the next week or so.

Will 0.11.2 have these OPs? Or they are only planned in future like sidechains OP?


Title: Re: OP_XXX: How to take current block height?
Post by: gmaxwell on November 05, 2015, 06:40:11 PM
Will 0.11.2 have these OPs? Or they are only planned in future like sidechains OP?
Yes and yes.

It's a soft fork, like sidechains support. Its activation will begin shortly, with the releases of 0.11.2 and 0.10.4.


Title: Re: OP_XXX: How to take current block height?
Post by: jl2012 on November 06, 2015, 03:42:24 AM
Will 0.11.2 have these OPs? Or they are only planned in future like sidechains OP?
Yes and yes.

It's a soft fork, like sidechains support. Its activation will begin shortly, with the releases of 0.11.2 and 0.10.4.


Can't wait any longer. This is the first new function added to Bitcoin since its creation (P2SH did not introduce new function)


Title: Re: OP_XXX: How to take current block height?
Post by: jl2012 on November 06, 2015, 04:02:49 AM
I want to make conditional output script, something like this:

Code:
IF (current_block_height < 400000)
{
   check_multisig(2,3);
}
ELSE
{
   usual OP_CHECKSIG condition;
}

There are many OP_XXX instructions, but there is no way to get current height of blockchain, or height of block where output script is stored.

May be there is easy way to get such data? :)

You example is not possible even with OP_CLTV. The nearest thing is:

Code:
OP_IF 2 <pubkey1> <pubkey2> <pubkey3> 3 OP_CHECKMULTISIG OP_ELSE 399999 OP_CLTV OP_DROP <pubkey4> OP_CHECKSIG OP_ENDIF
, which means:

Code:
IF (current_block_height < 400000)
{
   check_multisig(2,3);
}
ELSE
{
   (usual OP_CHECKSIG condition) OR (check_multisig(2,3));
}

At anytime, it could be spent with this scriptSig

Code:
0 <sig1> <sig2> 1

When block height is >= 400000, by setting the nLockTime >= 399999, it could be spent with this scriptSig

Code:
<sig4> 0