比特币源码阅读(交易-COutPoint)
【比特币源码阅读(交易-COutPoint)】文档:https://en.bitcoin.it/wiki/Protocol_documentation
交易的输入是另外一笔交易的输出,它的结构如下图:
文章图片
outpoint.png 对应的源码:
src/primitives/transaction.h
/** An outpoint - a combination of a transaction hash and an index n into its vout */
class COutPoint
{
public:
uint256 hash;
//out所在交易的hash
uint32_t n;
//所在索引COutPoint(): n((uint32_t) -1) { }
COutPoint(const uint256& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }ADD_SERIALIZE_METHODS;
//序列化template
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(hash);
READWRITE(n);
}void SetNull() { hash.SetNull();
n = (uint32_t) -1;
} //重置
bool IsNull() const { return (hash.IsNull() && n == (uint32_t) -1);
}friend bool operator<(const COutPoint& a, const COutPoint& b) //小于
{
int cmp = a.hash.Compare(b.hash);
//这里hash判断大小有意义么?
return cmp < 0 || (cmp == 0 && a.n < b.n);
}friend bool operator==(const COutPoint& a, const COutPoint& b)//相等的条件
{
return (a.hash == b.hash && a.n == b.n);
}friend bool operator!=(const COutPoint& a, const COutPoint& b) //不相等的条件
{
return !(a == b);
}std::string ToString() const;
};
推荐阅读
- Android事件传递源码分析
- Quartz|Quartz 源码解析(四) —— QuartzScheduler和Listener事件监听
- [源码解析]|[源码解析] NVIDIA HugeCTR,GPU版本参数服务器---(3)
- ffmpeg源码分析01(结构体)
- Java程序员阅读源码的小技巧,原来大牛都是这样读的,赶紧看看!
- Vue源码分析—响应式原理(二)
- 华雨欢(传统投资市场回暖,币市暴涨暴跌后回归震荡)
- SwiftUI|SwiftUI iOS 瀑布流组件之仿CollectionView不规则图文混合(教程含源码)
- java|java b2b2c shop 多用户商城系统源码- config 修改配置
- Spring源码解析_属性赋值