script

package
v0.0.0-...-1c741c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ContractExecutionDelay = 144

ContractExecutionDelay is a delay used in ContractExecutionScript

Variables

This section is empty.

Functions

func ContractExecutionScript

func ContractExecutionScript(puba, pubb, pubm *btcec.PublicKey) ([]byte, error)

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.

https://adiabat.github.io/dlc.pdf

func FundScript

func FundScript(pub1, pub2 *btcec.PublicKey) (script []byte, err error)

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

func P2WPKHpkScript(pub *btcec.PublicKey) ([]byte, error)

P2WPKHpkScript creates a withenss script for given pubkey.

ScriptCode:

OP_0 + HASH160(<public key>)

func P2WPKHpkScriptFromAddress

func P2WPKHpkScriptFromAddress(addr btcutil.Address) ([]byte, error)

P2WPKHpkScriptFromAddress creates a witness script for given address

func P2WSHpkScript

func P2WSHpkScript(script []byte) ([]byte, error)

P2WSHpkScript creates a witness script for given script.

ScriptCode:

OP_0 + SHA256(script)

func WitnessForCEScript

func WitnessForCEScript(
	sign []byte, script []byte) wire.TxWitness

WitnessForCEScript constructs a witness that unlocks a contract execution script. This function use the OP_IF block

func WitnessForCEScriptAfterDelay

func WitnessForCEScriptAfterDelay(
	sign []byte, script []byte) wire.TxWitness

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

func WitnessForFundScript(sign1, sign2, sc []byte) wire.TxWitness

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL