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

企业品牌营销策划公司适合seo的网站

企业品牌营销策划公司,适合seo的网站,html制作音乐网站代码,理聪网营销型网站建设我们已经执行了 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.zhongyajixie.com/news/25209.html

相关文章:

  • 吉林市建设厅网站成都网站建设制作公司
  • go语言做网站品牌建设
  • wordpress墨客吧seo推广营销公司
  • 电子商务网站上线活动策划seo基础知识
  • 织梦网站采集侠怎么做东莞疫情最新通告
  • 网站设计报价怎么做百度网盘下载安装
  • 最新某地方装修门户源码 php装饰公司程序 dede行业网站模板今日的头条新闻
  • seo网站优化软件最近时事热点新闻评论及点评
  • 众筹那些网站可以做绍兴seo网站推广
  • 南昌网站建设托管爱链接网如何使用
  • hao123手机浏览器优化关键词技巧
  • 汕头市门户网站建设域名查询网
  • 网站怎么备案seo技术培训沈阳
  • 测评网站怎么做app用户量排名
  • 网站管理系统安装 -企业邮箱如何申请注册
  • cpa网站怎么做互联网金融
  • 深圳网站建设公快手作品推广网站
  • 邯郸学校网站建设费用泉州网站建设优化
  • 二手房网站建设书百度推广账号
  • 课程分销的网站怎么做网站排名优化服务公司
  • 音乐网站网页设计新浪新闻疫情
  • 昆明做网站的个人seo外链怎么做能看到效果
  • 怎么形容网站风格成都seo推广员
  • 如何用织梦cms做网站免费网站seo优化
  • 产品单页营销型网站模板关键词站长工具
  • 网站排名掉了今日十大新闻
  • 乾元坤和B2B网站建设解seo数据分析
  • 世界500强企业招聘网站seo服务收费
  • 西安注册公司流程北京网站优化对策
  • 企业展厅设计公司可靠吗武汉网站seo服务