当前位置: 首页 > news >正文

外贸做包装袋哪个网站好网络公司seo教程

外贸做包装袋哪个网站好,网络公司seo教程,深圳龙华区有什么好玩的地方,厦门比较好的网站设计公司我们已经执行了 Bitcoin SV 和 Bitcoin Core 之间的首次原子交换。 这一成就代表了比特币 SV 的重大进步,以去信任的方式促进了与其他区块链的无缝互操作性。 图片源自Gemini 在上一篇文章中,我们解释了原子交换的高级理论。 我们深入研究了使用哈希时间…

我们已经执行了 Bitcoin SV 和 Bitcoin Core 之间的首次原子交换。 这一成就代表了比特币 SV 的重大进步,以去信任的方式促进了与其他区块链的无缝互操作性。

图片源自Gemini

图片源自Gemini

在上一篇文章中,我们解释了原子交换的高级理论。 我们深入研究了使用哈希时间锁定合约(HTLC)在 BSV 和 BTC 之间进行原子交换的实际示例。 让我们将此过程分解为四个基本步骤,每个步骤都包含您可以自己运行的代码片段。

第 1 步:Alice 在 BTC 上发起交易

该过程从 Alice 开始,她选择一个随机整数 x 并使用 SHA-256 算法创建一个哈希值 (xHash)。 接下来,Alice 部署了一个 Pay-to-Witness-Script-Hash (P2WSH) 交易,其中包括她想要与 Bob 交易的 BTC 数量。

我们使用 bitcoinutils 库构建 Alice 的交易:

def main():# always remember to setup the networksetup('testnet')# TODO: remember to adjust the values marked by "TODO" to your use case.alicePriv = PrivateKey('TODO')alicePub = alicePriv.get_public_key()bobPub = PublicKey('TODO')txid = 'TODO'  # Previous transaction IDvout = 2  # Previous transaction ouput indexamount = 0.00001850   # Amount in outputfee = 0.00000125      # Fee in new transactionx = 'f00cfd8df5f92d5e94d1ecbd9b427afd14e03f8a3292ca4128cd59ef7b9643bc'xHash = '1908c59a71781b7a44182ec39dd84a8a9e13dc31691fead8631730f5f5ab7b65'nBlocksLocked = '06'  # 6 blocks ~ 1 hr# HTLC script:htlc_redeem_script = Script(['OP_IF','OP_SHA256',xHash,'OP_EQUALVERIFY',bobPub.to_hex(),'OP_CHECKSIG','OP_ELSE',nBlocksLocked,'OP_CHECKSEQUENCEVERIFY','OP_DROP',alicePriv.get_public_key().to_hex(),'OP_CHECKSIG','OP_ENDIF'])toAddress = P2wshAddress.from_script(htlc_redeem_script)# Create transaction input from tx id of utxo.txIn = TxInput(txid, vout)redeem_script1 = Script(['OP_DUP', 'OP_HASH160', alicePub.to_hash160(), 'OP_EQUALVERIFY', 'OP_CHECKSIG'])# Create transaction output, which contains the P2WSH for the HTLC script.txOut = TxOutput(to_satoshis(amount - fee), toAddress.to_script_pub_key())# Create transaction.tx = Transaction([txIn], [txOut], has_segwit=True)# Sign transaction.sig1 = alicePriv.sign_segwit_input(tx, 0, redeem_script1, to_satoshis(amount))tx.witnesses.append(Script([sig1, alicePub.to_hex()]))# Print raw signed transaction ready to be broadcast.print("\nRaw signed transaction:\n" + tx.serialize())print("\nTxId:", tx.get_txid())

执行后,代码将打印原始的序列化交易,我们可以使用 Blockstream 的区块浏览器将其广播到 BTC 网络。

该 P2WSH 交易脚本由条件子句组成,这些条件子句包括需要 Bob 的公钥和秘密 x,或者 Alice 的签名和花费交易的时间延迟。

Bob 在 BTC 上进行应答

作为回应,Bob 在 BSV 区块链上部署了等效的 sCrypt 智能合约,其中包含他准备与 Alice 交换的 BSV 金额。

class HashTimeLockContract extends SmartContract {@prop() readonly alicePubKey: PubKey@prop() readonly bobPubKey: PubKey@prop() readonly hashX: Sha256@prop() readonly timeout: bigint // Can be a timestamp or block height.// hash lock@method()public unlock(x: ByteString, aliceSig: Sig) {// Check if H(x) == this.hashXassert(sha256(x) == this.hashX, 'Invalid secret.')// Verify Alices signature.assert(this.checkSig(aliceSig, this.alicePubKey))}// time lock@method()public cancel(bobSig: Sig) {assert(this.ctx.locktime >= this.timeout, 'locktime has not yet expired')// Verify Bobs signature.assert(this.checkSig(bobSig, this.bobPubKey))}
}

Bob 获得了 x 的哈希值,但不是 x 本身,以及 Alice 的公钥。 然后,他使用以下部署代码部署智能合约:


const alicePubKey = bsv.PublicKey.fromHex('TODO')const bobPrivKey = bsv.PrivateKey.fromWIF('TODO')
const bobPubKey = bobPrivKey.publicKeyconst amount = 100000  // TODO: amount of BSV to be locked in the contractconst xHash = toByteString('1908c59a71781b7a44182ec39dd84a8a9e13dc31691fead8631730f5f5ab7b65'
)
const lockTimeMin = 1688715000 // Timestamp, after which Bob can withdraw his funds.await CrossChainSwap.compile()// Connect Bob signer.
const provider = new DefaultProvider(bsv.Networks.testnet)
const signer = new TestWallet(bobPrivKey, provider)const crossChainSwap = new CrossChainSwap(PubKey(alicePubKey.toHex()),PubKey(bobPubKey.toHex()),xHash,BigInt(lockTimeMin)
)
await crossChainSwap.connect(signer)// Contract deployment.
const deployTx = await crossChainSwap.deploy(amount)
console.log('CrossChainSwap contract deployed: ', deployTx.id)

第三步:Alice 解锁 Bob 的合约

成功部署 sCrypt 合约后,Alice 现在可以通过泄露秘密 x 来调用 Bob 合约的公共方法 unlock()。 结果,Alice 拥有了 Bob 的 BSV。

const deployedContractTXID = 'TODO'
const x = toByteString('f00cfd8df5f92d5e94d1ecbd9b427afd14e03f8a3292ca4128cd59ef7b9643bc')// Alice unlocks contract and takes the funds.
const provider = new DefaultProvider(bsv.Networks.testnet)
const signer = new TestWallet(alicePrivKey, provider)const tx = await signer.provider.getTransaction(deployedContractTXID)
const crossChainSwap = CrossChainSwap.fromTx(tx, 0)
await crossChainSwap.connect(signer)const { tx: callTx, atInputIndex } =await crossChainSwap.methods.unlock(x,(sigResps) => findSig(sigResps, alicePubKey),{pubKeyOrAddrToSign: alicePubKey,} as MethodCallOptions<CrossChainSwap>)
console.log('CrossChainSwap "unlock" method called: ', callTx.id)

第四步:Bob 取回 Alice 的 BTC

一旦 Alice 透露了 x,Bob 就可以用它来解锁 BTC 区块链上的 P2WSH UTXO。 这个过程允许鲍勃索取爱丽丝的比特币,从而完成原子交换。

def main():# always remember to setup the networksetup('testnet')# TODO: Set values:bobPriv = PrivateKey('TODO')bobPub = bobPriv.get_public_key()alicePub = PublicKey('TODO')txid = 'TODO'  # Previous transaction IDvout = 0 # Previous transaction ouput indexamount = 0.00001725   # Amount in outputfee = 0.00000125      # Fee in new transactionx = 'f00cfd8df5f92d5e94d1ecbd9b427afd14e03f8a3292ca4128cd59ef7b9643bc'xHash = '1908c59a71781b7a44182ec39dd84a8a9e13dc31691fead8631730f5f5ab7b65'nBlocksLocked = '06'  # 6 blocks ~ 1 hrtoAddress = P2wpkhAddress.from_address('TODO')# HTLC Script:htlc_redeem_script = Script(['OP_IF','OP_SHA256',xHash,'OP_EQUALVERIFY',bobPub.to_hex(),'OP_CHECKSIG','OP_ELSE',nBlocksLocked,'OP_CHECKSEQUENCEVERIFY','OP_DROP',alicePub.to_hex(),'OP_CHECKSIG','OP_ENDIF'])fromAddress = P2wshAddress.from_script(htlc_redeem_script)# Create transaction input from tx id of UTXOtxin = TxInput(txid, vout)txOut1 = TxOutput(to_satoshis(amount - fee), toAddress.to_script_pub_key())tx = Transaction([txin], [txOut1], has_segwit=True)# NOTE: In P2WSH, the argument for OP_IF and OP_NOTIF MUST be exactly an empty vector or 0x01, or the script evaluation fails immediately.# Normal unlock:sig1 = bobPriv.sign_segwit_input(tx, 0, htlc_redeem_script, to_satoshis(amount))tx.witnesses.append(Script([sig1,x,'01',  # OP_TRUEhtlc_redeem_script.to_hex()]))# print raw signed transaction ready to be broadcastedprint("\nRaw signed transaction:\n" + tx.serialize())print("\nTxId:", tx.get_txid())

我们可以广播打印的原始交易并完成交换。

争议解决

在发生争议的情况下,Alice 和 Bob 都可以在一段时间后提取资金。

此功能提供了一种故障安全机制,可确保在交换不成功或有争议的情况下不会永久锁定资金。 时间限制为双方解锁各自的合同提供了足够的窗口。

在爱丽丝的例子中,我们可以修改见证人的构造:

# ...# Create transaction input from tx id of UTXO.
txin = TxInput(txid, vout, sequence=bytes.fromhex('FFFFFFFE'))# ...locktime = bytes.fromhex('64A7F990') # 1688730000
tx = Transaction([txin], [txOut1], has_segwit=True, locktime=locktime)# Withdrawal:
sig1 = alicePriv.sign_segwit_input(tx, 0, htlc_redeem_script, to_satoshis(amount))
tx.witnesses.append(Script([sig1,'', # OP_FALSEhtlc_redeem_script.to_hex()]))#...

传递 OP_FALSE 作为第一个输入将在 OP_ELSE 之后执行脚本,这会检查时间锁定是否已过期。

同样,在 Bob 的情况下,我们修改代码以调用 cancel 方法:


// Bob withdraws after timeout passed.
const { tx: callTx, atInputIndex } =await crossChainSwap.methods.cancel((sigResps) => findSig(sigResps, bobPubKey),{lockTime: 1688730000,pubKeyOrAddrToSign: bobPubKey,} as MethodCallOptions<CrossChainSwap>)
console.log('CrossChainSwap "cancel" method called: ', callTx.id)

首次成功跨链BTC-BSV互换

我们在 BSV 和 BTC 主网之间进行了首次成功的原子交换。

  • BTC 上的初始 P2WSH 交易:af7a8c31e489c18d6fe46141cf2cbc777aeb23672679eb199bde4813d6fe41d4

  • BSV 上等效的 sCrypt 智能合约交易:8598d203e8bdd45b7025e334cdebdef06be88381dec245d95108e658e8373f9c

  • Alice 调用 unlock 方法:68c2c5a91645112df6b62a5ee6ea9e0e22f29499b88c9ccffc23f8f86ec63d09

  • 鲍勃解锁了 BTC:9c697bf8f0d2c11285cfab3a2b8a856a1c18ae048d481c7bb3f93f9ccd2dbaad

这也是一个未完成的交换示例。 爱丽丝和鲍勃都收回了他们的资金。

  • BTC: 395dde14e489208302c1d6ac3b4fc0db890c000fd79f3e836fc74043a54480ff
  • BSV: 12e701237a1f6da2b69f1d4dab2b1208d3f6003f7b45ef178c5c7d9e00c54273

本文中显示的所有代码都可以在我们的 GitHub 上找到。

http://www.hengruixuexiao.com/news/41118.html

相关文章:

  • 运用.net做网站旺道营销软件
  • 商城网站seo百度网盘搜索免费资源
  • 开网站做赌博赚钱吗网站营销网站营销推广
  • 宁波人才网济南seo快速霸屏
  • 做网站的股哥长沙百度推广优化排名
  • 做色情网站盈利会怎么样百度学术论文查重官网
  • 网站开发制作学徒app开发工具哪个好
  • 固镇建设局网站商丘seo博客
  • 招商网站建设长沙网站seo哪家公司好
  • 北京顺义去哪找做网站的企业产品营销策划推广
  • 游戏发号网站源码百度竞价推广怎么做效果好
  • 做邮轮上哪个网站订票好免费单页网站在线制作
  • wordpress 主题 mnews优化营商环境评价
  • 网络推广培训网网站查询seo
  • 淘宝网站建设策划书百度搜索指数排行
  • b2b网站策划书哈尔滨最新
  • B2B外贸网站模板google chrome 网络浏览器
  • 网络营销的方法和手段seo快速排名优化
  • 政府网站模板php今天头条新闻100条
  • HTTPS网站做CDN站长工具麻豆
  • 网站开发的五个阶段企业网站有哪些
  • 做网站定金是多少网络推广培训班哪家好
  • 体育网站建设需求手机优化大师怎么退款
  • 学做网站要学什么东西seo网站优化培训找哪些
  • oa办公系统是什么意思武汉排名seo公司
  • vs2013可以做网站么ciliba最佳磁力搜索引擎
  • 企业专业网站设计公成人馆店精准引流怎么推广
  • 大众服务器网站搜索引擎优化seo多少钱
  • wordpress任务宁波seo网络推广咨询价格
  • 网站注册系统怎么做电子商务网站建设与维护