• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript bitcoinjs-lib.payments类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中bitcoinjs-lib.payments的典型用法代码示例。如果您正苦于以下问题:TypeScript payments类的具体用法?TypeScript payments怎么用?TypeScript payments使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了payments类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: makeRevokeSkeleton

export function makeRevokeSkeleton(fullyQualifiedName: string) {
  // Returns a revoke tx skeleton
  //    with 1 output: 1. the Blockstack revoke OP_RETURN
  //
  // You MUST make the first input a UTXO from the current OWNER
  //
  // Returns an unsigned serialized transaction
  /*
   Format:

   0    2  3                             39
   |----|--|-----------------------------|
   magic op   name.ns_id (37 bytes)

   output 0: the revoke code
  */

  const opRet = Buffer.alloc(3)

  const nameBuff = Buffer.from(fullyQualifiedName, 'ascii')

  opRet.write(opEncode('~'), 0, 3, 'ascii')

  const opReturnBuffer = Buffer.concat([opRet, nameBuff])
  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:31,代码来源:skeletons.ts


示例2: makeNameImportSkeleton

export function makeNameImportSkeleton(name: string, recipientAddr: string, zonefileHash: string) {
  /*
   Format:

    0    2  3                             39
    |----|--|-----------------------------|
    magic op   name.ns_id (37 bytes)

   Output 0: the OP_RETURN
   Output 1: the recipient
   Output 2: the zonefile hash
 */
  if (zonefileHash.length !== 40) {
    throw new Error('Invalid zonefile hash: must be 20 bytes hex-encoded')
  }

  const network = config.network
  const opReturnBuffer = Buffer.alloc(3 + name.length)
  opReturnBuffer.write(opEncode(';'), 0, 3, 'ascii')
  opReturnBuffer.write(name, 3, name.length, 'ascii')

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output

  const tx = makeTXbuilder()
  const zonefileHashB58 = bitcoin.address.toBase58Check(
    Buffer.from(zonefileHash, 'hex'), network.layer1.pubKeyHash
  )

  tx.addOutput(nullOutput, 0)
  tx.addOutput(recipientAddr, DUST_MINIMUM)
  tx.addOutput(zonefileHashB58, DUST_MINIMUM)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:34,代码来源:skeletons.ts


示例3: makeNamespaceRevealSkeleton

export function makeNamespaceRevealSkeleton(
  namespace: BlockstackNamespace, revealAddress: string
) {
  /*
   Format:

   0     2   3    7     8     9    10   11   12   13   14    15    16    17       18      20     39
   |-----|---|----|-----|-----|----|----|----|----|----|-----|-----|-----|--------|-------|-------|
   magic  op  life coeff. base 1-2  3-4  5-6  7-8  9-10 11-12 13-14 15-16 nonalpha version  ns ID
                                                  bucket exponents        no-vowel
                                                                          discounts
   
   output 0: namespace reveal code
   output 1: reveal address
  */
  const hexPayload = namespace.toHexPayload()

  const opReturnBuffer = Buffer.alloc(3 + hexPayload.length / 2)
  opReturnBuffer.write(opEncode('&'), 0, 3, 'ascii')
  opReturnBuffer.write(hexPayload, 3, hexPayload.length / 2, 'hex')

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)
  tx.addOutput(revealAddress, DUST_MINIMUM)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:29,代码来源:skeletons.ts


示例4: makeTokenTransferSkeleton

export function makeTokenTransferSkeleton(recipientAddress: string, consensusHash: string,
                                          tokenType: string, tokenAmount: BN,
                                          scratchArea: string
) {
  /*
   Format:

    0     2  3              19         38          46                        80
    |-----|--|--------------|----------|-----------|-------------------------|
    magic op  consensus_hash token_type amount (BE) scratch area
                             (ns_id)

    output 0: token transfer code
    output 1: recipient address
  */
  if (scratchArea.length > 34) {
    throw new Error('Invalid scratch area: must be no more than 34 bytes')
  }

  const opReturnBuffer = Buffer.alloc(46 + scratchArea.length)

  const tokenTypeHex = Buffer.from(tokenType).toString('hex')
  const tokenTypeHexPadded = `00000000000000000000000000000000000000${tokenTypeHex}`.slice(-38)

  const tokenValueHex = tokenAmount.toString(16, 2)

  if (tokenValueHex.length > 16) {
    // exceeds 2**64; can't fit
    throw new Error(`Cannot send tokens: cannot fit ${tokenAmount.toString()} into 8 bytes`)
  }

  const tokenValueHexPadded = `0000000000000000${tokenValueHex}`.slice(-16)

  opReturnBuffer.write(opEncode('$'), 0, 3, 'ascii')
  opReturnBuffer.write(consensusHash, 3, consensusHash.length / 2, 'hex')
  opReturnBuffer.write(tokenTypeHexPadded, 19, tokenTypeHexPadded.length / 2, 'hex')
  opReturnBuffer.write(tokenValueHexPadded, 38, tokenValueHexPadded.length / 2, 'hex')
  opReturnBuffer.write(scratchArea, 46, scratchArea.length, 'ascii')

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)
  tx.addOutput(recipientAddress, DUST_MINIMUM)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:47,代码来源:skeletons.ts


示例5: makeTransferSkeleton

export function makeTransferSkeleton(
  fullyQualifiedName: string, consensusHash: string, newOwner: string,
  keepZonefile: boolean = false
) {
  // Returns a transfer tx skeleton.
  //   with 2 outputs : 1. the Blockstack Transfer OP_RETURN data
  //                    2. the new owner with a DUST_MINIMUM value (5500 satoshi)
  //
  // You MUST make the first input a UTXO from the current OWNER
  //
  // Returns an unsigned serialized transaction.
  /*
    Format

    0     2  3    4                   20              36
    |-----|--|----|-------------------|---------------|
    magic op keep  hash128(name.ns_id) consensus hash
             data?

    output 0: transfer code
    output 1: new owner
  */
  const opRet = Buffer.alloc(36)
  let keepChar = '~'
  if (keepZonefile) {
    keepChar = '>'
  }

  opRet.write(opEncode('>'), 0, 3, 'ascii')
  opRet.write(keepChar, 3, 1, 'ascii')

  const hashed = hash128(Buffer.from(fullyQualifiedName, 'ascii'))
  hashed.copy(opRet, 4)
  opRet.write(consensusHash, 20, 16, 'hex')

  const opRetPayload = bitcoin.payments.embed({ data: [opRet] }).output

  const tx = makeTXbuilder()

  tx.addOutput(opRetPayload, 0)
  tx.addOutput(newOwner, DUST_MINIMUM)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:44,代码来源:skeletons.ts


示例6: makeUpdateSkeleton

export function makeUpdateSkeleton(
  fullyQualifiedName: string, consensusHash: string, valueHash: string
) {
  // Returns an update tx skeleton.
  //   with 1 output : 1. the Blockstack update OP_RETURN
  //
  // You MUST make the first input a UTXO from the current OWNER
  //
  // Returns an unsigned serialized transaction.
  //
  // output 0: the revoke code
  /*
    Format:

    0     2  3                                   19                      39
    |-----|--|-----------------------------------|-----------------------|
    magic op  hash128(name.ns_id,consensus hash) hash160(data)

    output 0: update code
  */

  const opRet = Buffer.alloc(39)

  const nameBuff = Buffer.from(fullyQualifiedName, 'ascii')
  const consensusBuff = Buffer.from(consensusHash, 'ascii')

  const hashedName = hash128(Buffer.concat(
    [nameBuff, consensusBuff]
  ))

  opRet.write(opEncode('+'), 0, 3, 'ascii')
  hashedName.copy(opRet, 3)
  opRet.write(valueHash, 19, 20, 'hex')

  const opRetPayload = bitcoin.payments.embed({ data: [opRet] }).output

  const tx = makeTXbuilder()

  tx.addOutput(opRetPayload, 0)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:42,代码来源:skeletons.ts


示例7: makeNamespaceReadySkeleton

export function makeNamespaceReadySkeleton(namespaceID: string) {
  /*
   Format:

   0     2  3  4           23
   |-----|--|--|------------|
   magic op  .  ns_id

   output 0: namespace ready code
   */
  const opReturnBuffer = Buffer.alloc(3 + namespaceID.length + 1)
  opReturnBuffer.write(opEncode('!'), 0, 3, 'ascii')
  opReturnBuffer.write(`.${namespaceID}`, 3, namespaceID.length + 1, 'ascii')

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:21,代码来源:skeletons.ts


示例8: makeAnnounceSkeleton

export function makeAnnounceSkeleton(messageHash: string) {
  /*
    Format:

    0    2  3                             23
    |----|--|-----------------------------|
    magic op   message hash (160-bit)

    output 0: the OP_RETURN
  */
  if (messageHash.length !== 40) {
    throw new Error('Invalid message hash: must be 20 bytes hex-encoded')
  }

  const opReturnBuffer = Buffer.alloc(3 + messageHash.length / 2)
  opReturnBuffer.write(opEncode('#'), 0, 3, 'ascii')
  opReturnBuffer.write(messageHash, 3, messageHash.length / 2, 'hex')

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)
  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:24,代码来源:skeletons.ts


示例9: getAddressFromBIP32Node

 static getAddressFromBIP32Node(node: BIP32) {
   return bitcoin.payments.p2pkh({ pubkey: node.publicKey }).address
 }
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:3,代码来源:wallet.ts


示例10: makeNamespacePreorderSkeleton

export function makeNamespacePreorderSkeleton(
  namespaceID: string, consensusHash: string, preorderAddress: string,
  registerAddress: string, burn: AmountType
) {
  // Returns a namespace preorder tx skeleton.
  // Returns an unsigned serialized transaction.
  /*
   Formats:

   Without STACKS:

   0     2   3                                      23               39
   |-----|---|--------------------------------------|----------------|
   magic op  hash(ns_id,script_pubkey,reveal_addr)   consensus hash


   with STACKs:

   0     2   3                                      23               39                         47
   |-----|---|--------------------------------------|----------------|--------------------------|
   magic op  hash(ns_id,script_pubkey,reveal_addr)   consensus hash    token fee (big-endian)

   output 0: namespace preorder code
   output 1: change address
   otuput 2: burn address
  */

  const burnAmount = asAmountV2(burn)
  if (burnAmount.units !== 'BTC' && burnAmount.units !== 'STACKS') {
    throw new Error(`Invalid burnUnits ${burnAmount.units}`)
  }

  const network = config.network
  const burnAddress = network.getDefaultBurnAddress()
  const namespaceIDBuff = Buffer.from(decodeB40(namespaceID), 'hex') // base40
  const scriptPublicKey = bitcoin.address.toOutputScript(preorderAddress, network.layer1)
  const registerBuff = Buffer.from(registerAddress, 'ascii')

  const dataBuffers = [namespaceIDBuff, scriptPublicKey, registerBuff]
  const dataBuff = Buffer.concat(dataBuffers)

  const hashed = hash160(dataBuff)
  
  let btcBurnAmount = DUST_MINIMUM
  let opReturnBufferLen = 39
  if (burnAmount.units === 'STACKS') {
    opReturnBufferLen = 47
  } else {
    btcBurnAmount = burnAmount.amount.toNumber()
  }

  const opReturnBuffer = Buffer.alloc(opReturnBufferLen)
  opReturnBuffer.write(opEncode('*'), 0, 3, 'ascii')
  hashed.copy(opReturnBuffer, 3)
  opReturnBuffer.write(consensusHash, 23, 16, 'hex')

  if (burnAmount.units === 'STACKS') {
    const burnHex = burnAmount.amount.toString(16, 2)
    const paddedBurnHex = `0000000000000000${burnHex}`.slice(-16)
    opReturnBuffer.write(paddedBurnHex, 39, 8, 'hex')
  }

  const nullOutput = bitcoin.payments.embed({ data: [opReturnBuffer] }).output
  const tx = makeTXbuilder()

  tx.addOutput(nullOutput, 0)
  tx.addOutput(preorderAddress, DUST_MINIMUM)
  tx.addOutput(burnAddress, btcBurnAmount)

  return tx.buildIncomplete()
}
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:71,代码来源:skeletons.ts



注:本文中的bitcoinjs-lib.payments类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript bitcore-client.Wallet类代码示例发布时间:2022-05-25
下一篇:
TypeScript bitcoinjs-lib.crypto类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap