Skip to content

Instantly share code, notes, and snippets.

@dr-orlovsky
Created January 24, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dr-orlovsky/b353be907e3e156864b75bbc854ceddf to your computer and use it in GitHub Desktop.
Save dr-orlovsky/b353be907e3e156864b75bbc854ceddf to your computer and use it in GitHub Desktop.
LockScript
///
/// The following charts represent possible relations between script types:
///
/// ```text
/// [txout.pubkeyScript]
/// PubkeyScript --?--(P2PK, custom scripts)--> LockScript <--+-------+---+---------+
/// | | | |
/// [txin.sigScript] | | | |
/// SigScript --+--?!----------(P2PKH: #=PubkeyHash)----------+ | | |
/// | | | |
/// +--?!--> RedeemScript --+--?!--(P2SH: #=ScriptHash)---+ | |
/// | | |
/// (P2W{SH/PKH}-within-P2SH:) (#=WPubkeyHash/WitnessProgram) |
/// | | |
/// [?txin.witness]~~~(P2W{SH/PKH}:)~~~~+--?!--> WitnessScript --+--------+ (P2TR:)
/// | |
/// +--?--> TapScript--+
///
/// ```
/// Legend:
/// * `[<source>]`: data source
/// * `[?<source>]`: data source which may be absent
/// * `--+--`: algorithmic branching (alternative computation options)
/// * `--?-->`: a conversion exists, but it may fail (returns `Option` or `Result`)
/// * `--?!-->`: a conversion exists, but it may fail; however one of alternative branches must
/// always succeed
/// * `----->`: a conversion exists which can't fail
/// * `(<type>:)`: a type of the scripting mechanism
/// * `-(#<type>)->`: the hash of the value following `->` must match to the value of the `<type>`
///
// STYLE: Multiline string literals with `"""` are still not supported for the meta-type macro tokens
wrapper!(LockScript, _LockScriptPhantom, Script, doc="\
The deepest nested version of Bitcoin script containing no hashes of other scripts, including \
P2SH redeemScript hashes or witnessProgramm (hash or wintness script), or public keys");
wrapper!(PubkeyScript, _PubkeyScriptPhantom, Script, doc="\
A content of `scriptPubkey` from a transaction output");
wrapper!(SigScript, _SigScriptPhantom, Script, doc="\
A content of `sigScript` from a transaction input");
wrapper!(WitnessScript, _WitnessScriptPhantom, Script, doc="\
A part of the `witness` field from a transaction input according to BIP-141");
wrapper!(RedeemScript, _RedeemScriptPhantom, Script, doc="\
redeemScript part of the witness program or sigScript which is hashed for P2(W)SH output");
wrapper!(TapScript, _TapScriptPhantom, Script, doc="\
Any valid branch of Tapscript (BIP-342)");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment