scriptPubKey and scriptSig

First of all two matching scripts are used in two different transactions, one that transfers funds to an address (Transaction A) and one that spends those funds (Transaction B). The scriptPubKey is created by the user that creates Transaction A. It basically adds a claiming condition to the output that is being created. A user may only claim and thus spend the bitcoins associated with the output if he can prove that he owns the output.

This is where Transaction B and the scriptSig comes into play. Assuming a user wants to send some funds somewhere. He creates a new transaction, and adds outputs to it until he has enough to cover the desired amount. Now he has to prove that he owns those outputs, which he does by providing the output that is needed to claim them, i.e., the public key matching the address and the signatures with the matching private key.

The sender of Transaction A does not yet know the public key, but does know a hash of the public key, because he knows the address he wants to send to. The address is nothing more than the hash of the public key. So the sender now knows all he needs to be able to send the funds to the receiver.

When the receiver wants to spend the funds again he provides the input to the scriptPubKey. As you can see the scriptPubKey consists of taking the public key that was pushed on the stack, duplicating it, hashing it and comparing it to the hash of the public key the output was destined for. If they match we still have both the signature and the public key on the stack, which are used by OP_CHECKSIG to see whether the input had a valid signature attached.

Take this transaction for example. It claims one output, by providing the public key and the matching signature. It then creates two new outputs and specifies the conditions for the next user to claim them.

 

https://bitcoin.stackexchange.com/questions/8250/what-is-relation-between-scriptsig-and-scriptpubkey

转载于:https://www.cnblogs.com/feng9exe/p/9890461.html

根据GitHub上的Bitcoin项目编写UML代码是一个复杂的过程,因为Bitcoin项目包含多个模块和组件。以下是一个简化的UML类图示例,展示了Bitcoin项目中的几个关键类和它们之间的关系。 ```uml @startuml title Bitcoin UML Class Diagram class CBlock { - uint256 hash - int32_t nVersion - std::vector<CTransaction> vtx - uint32_t nTime - uint32_t nBits - uint32_t nNonce - AddTransaction(CTransaction tx) - GetHash() : uint256 } class CTransaction { - uint256 hash - int32_t nVersion - std::vector<CTxIn> vin - std::vector<CTxOut> vout - uint32_t nLockTime - GetHash() : uint256 } class CTxIn { - CAmount nValue - CScript scriptPubKey } class COutPoint { - uint256 hash - uint32_t n } class CScript { - std::vector<unsigned char> vch - Add(const std::vector<unsigned char>& data) - GetHash() : uint256 } CBlock "1" *-- "n" CTransaction : contains CTransaction "1" *-- "n" CTxIn : inputs CTransaction "1" *-- "n" CTxOut : outputs CTxIn "1" *-- "1" COutPoint : references CTxIn "1" *-- "1" CScript : scriptSig CTxOut "1" *-- "1" CScript : scriptPubKey @enduml ``` 这个UML类图展示了Bitcoin项目中的几个关键类及其关系: 1. `CBlock` 类表示一个区块,包含多个交易。 2. `CTransaction` 类表示一个交易,包含多个输入和输出。 3. `CTxIn` 类表示一个交易的输入,包含一个指向之前交易的输出和签名脚本。 4. `CTxOut` 类表示一个交易的输出,包含金额和公钥脚本。 5. `COutPoint` 类表示一个指向之前交易的输出的指针。 6. `CScript` 类表示一个脚本,包含一系列字节。 通过这个UML类图,可以更清晰地理解Bitcoin项目中的各个组件及其相互关系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值