Documentation ¶
Index ¶
- Constants
- func ContractExecutionScript(puba, pubb, pubm *btcec.PublicKey) ([]byte, error)
- func FundScript(pub1, pub2 *btcec.PublicKey) (script []byte, err error)
- func P2WPKHpkScript(pub *btcec.PublicKey) ([]byte, error)
- func P2WPKHpkScriptFromAddress(addr btcutil.Address) ([]byte, error)
- func P2WSHpkScript(script []byte) ([]byte, error)
- func WitnessForCEScript(sign []byte, script []byte) wire.TxWitness
- func WitnessForCEScriptAfterDelay(sign []byte, script []byte) wire.TxWitness
- func WitnessForFundScript(sign1, sign2, sc []byte) wire.TxWitness
- func WitnessSignature(tx *wire.MsgTx, idx int, amt int64, script []byte, priv *btcec.PrivateKey) ([]byte, error)
Constants ¶
const ContractExecutionDelay = 144
ContractExecutionDelay is a delay used in ContractExecutionScript
Variables ¶
This section is empty.
Functions ¶
func ContractExecutionScript ¶
ContractExecutionScript returns a contract execution script.
Script Code:
OP_IF <public key a + message public key> OP_ELSE delay(fix 144) OP_CHECKSEQUENCEVERIFY OP_DROP <public key b> OP_ENDIF OP_CHECKSIG
The if block can be passed when the contractor A has a valid oracle's sign to the message. But if the contractor sends this transaction without the oracle's valid sign, the else block will be used by the other party B after the delay time (1 day approximately). Please check the original paper for more details.
func FundScript ¶
FundScript is a 2-of-2 multisig script
ScriptCode:
OP_2 <public key first party> <public key second party> OP_2 OP_CHECKMULTISIG
func P2WPKHpkScript ¶
P2WPKHpkScript creates a withenss script for given pubkey.
ScriptCode:
OP_0 + HASH160(<public key>)
func P2WPKHpkScriptFromAddress ¶
P2WPKHpkScriptFromAddress creates a witness script for given address
func P2WSHpkScript ¶
P2WSHpkScript creates a witness script for given script.
ScriptCode:
OP_0 + SHA256(script)
func WitnessForCEScript ¶
WitnessForCEScript constructs a witness that unlocks a contract execution script. This function use the OP_IF block
func WitnessForCEScriptAfterDelay ¶
WitnessForCEScriptAfterDelay constructs a witness that unlocks a contract execution script. This function use the OP_ELSE block that can be valid after the delay
func WitnessForFundScript ¶
WitnessForFundScript constructs a witness for fund script
func WitnessSignature ¶
func WitnessSignature( tx *wire.MsgTx, idx int, amt int64, script []byte, priv *btcec.PrivateKey, ) ([]byte, error)
WitnessSignature returns a witness signature for given script
Note: txscript.RawTxInWitnessSignature converts a script from p2wkh to p2pkh implicitly. https://github.com/btcsuite/btcd/blob/master/txscript/script.go#L488 It's better to convert it on ourside explicitly.
Types ¶
This section is empty.