Skip to content

Commit

Permalink
Comments: More comments on functions/globals in standard.h.
Browse files Browse the repository at this point in the history
Zcash: Excludes comments for variables and functions we don't have:

- GetScriptForRawPubKey (bitcoin/bitcoin#6415)
- GetScriptForWitness (bitcoin/bitcoin#8149)
  • Loading branch information
Jim Posen authored and str4d committed Dec 4, 2019
1 parent 602960e commit 3c8c800
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/script/standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ const char* GetTxnOutputType(txnouttype t)
return NULL;
}

/**
* Return public keys or hashes from scriptPubKey, for 'standard' transaction types.
*/
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsigned char> >& vSolutionsRet)
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet)
{
// Templates
static multimap<txnouttype, CScript> mTemplates;
Expand Down
52 changes: 49 additions & 3 deletions src/script/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ class CScriptID : public uint160
CScriptID(const uint160& in) : uint160(in) {}
};

static const unsigned int MAX_OP_RETURN_RELAY = 83; //!< bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
/**
* Default setting for nMaxDatacarrierBytes. 80 bytes of data, +1 for OP_RETURN,
* +2 for the pushdata opcodes.
*/
static const unsigned int MAX_OP_RETURN_RELAY = 83;

/**
* A data carrying output is an unspendable output containing data. The script
* type is designated as TX_NULL_DATA.
*/
extern bool fAcceptDatacarrier;

/** Maximum size of TX_NULL_DATA scripts that this node considers standard. */
extern unsigned nMaxDatacarrierBytes;

/**
Expand All @@ -49,7 +60,7 @@ enum txnouttype
TX_PUBKEYHASH,
TX_SCRIPTHASH,
TX_MULTISIG,
TX_NULL_DATA,
TX_NULL_DATA, //!< unspendable OP_RETURN script that carries data
};

class CNoDestination {
Expand All @@ -58,7 +69,7 @@ class CNoDestination {
friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
};

/**
/**
* A txout script template with a specific destination. It is either:
* * CNoDestination: no destination set
* * CKeyID: TX_PUBKEYHASH destination
Expand All @@ -70,15 +81,50 @@ typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
/** Check whether a CTxDestination is a CNoDestination. */
bool IsValidDestination(const CTxDestination& dest);

/** Get the name of a txnouttype as a C string, or nullptr if unknown. */
const char* GetTxnOutputType(txnouttype t);

/**
* Parse a scriptPubKey and identify script type for standard scripts. If
* successful, returns script type and parsed pubkeys or hashes, depending on
* the type. For example, for a P2SH script, vSolutionsRet will contain the
* script hash, for P2PKH it will contain the key hash, etc.
*
* @param[in] scriptPubKey Script to parse
* @param[out] typeRet The script type
* @param[out] vSolutionsRet Vector of parsed pubkeys and hashes
* @return True if script matches standard template
*/
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);

/**
* Parse a standard scriptPubKey for the destination address. Assigns result to
* the addressRet parameter and returns true if successful. For multisig
* scripts, instead use ExtractDestinations. Currently only works for P2PK,
* P2PKH, and P2SH scripts.
*/
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);

/**
* Parse a standard scriptPubKey with one or more destination addresses. For
* multisig scripts, this populates the addressRet vector with the pubkey IDs
* and nRequiredRet with the n required to spend. For other destinations,
* addressRet is populated with a single value and nRequiredRet is set to 1.
* Returns true if successful. Currently does not extract address from
* pay-to-witness scripts.
*/
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);

/**
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty
* script for CNoDestination.
*/
CScript GetScriptForDestination(const CTxDestination& dest);
CScript GetScriptForRawPubKey(const CPubKey& pubkey);

/** Generate a multisig script. */
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey>& keys);

// insightexplorer
Expand Down

0 comments on commit 3c8c800

Please sign in to comment.