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

TypeScript stellar-sdk.Operation类代码示例

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

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



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

示例1:

import * as StellarSdk from 'stellar-sdk';

const sourceKey = StellarSdk.Keypair.random(); // $ExpectType Keypair
const destKey = StellarSdk.Keypair.random();
const account = new StellarSdk.Account(sourceKey.publicKey(), '1');
const transaction = new StellarSdk.TransactionBuilder(account)
    .addOperation(StellarSdk.Operation.accountMerge({destination: destKey.publicKey()}))
    .addMemo(new StellarSdk.Memo(StellarSdk.MemoText, "memo"))
    .build(); // $ExpectType () => Transaction
transaction; // $ExpectType Transaction

StellarSdk.StellarTomlResolver.resolve("example.com", {allowHttp: true, timeout: 100})
    .then(toml => toml.FEDERATION_SERVER);

const sig = StellarSdk.xdr.DecoratedSignature.fromXDR(Buffer.of(1, 2)); // $ExpectType DecoratedSignature
sig.hint(); // $ExpectType Buffer
sig.signature(); // $ExpectType Buffer

StellarSdk.Memo.none(); // $ExpectType Memo<"none">
StellarSdk.Memo.text('asdf'); // $ExpectType Memo<"text">
StellarSdk.Memo.id('asdf'); // $ExpectType Memo<"id">
StellarSdk.Memo.return('asdf'); // $ExpectType Memo<"return">
StellarSdk.Memo.hash('asdf'); // $ExpectType Memo<"hash">
StellarSdk.Memo.none().value; // $ExpectType null
StellarSdk.Memo.id('asdf').value; // $ExpectType string
StellarSdk.Memo.text('asdf').value; // $ExpectType string
StellarSdk.Memo.return('asdf').value; // $ExpectType Buffer
StellarSdk.Memo.hash('asdf').value; // $ExpectType Buffer

// P.S. don't use Memo constructor
(new StellarSdk.Memo(StellarSdk.MemoHash, 'asdf')).value; // $ExpectType AnyValue
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:31,代码来源:stellar-sdk-tests.ts


示例2: co

    return co(function *() {
      const [userKey, backupKey] = this.initiateRecovery(params);
      const isKrsRecovery = params.backupKey.startsWith('G') && !params.userKey.startsWith('G');
      const isUnsignedSweep = params.backupKey.startsWith('G') && params.userKey.startsWith('G');

      if (!stellar.StrKey.isValidEd25519PublicKey(params.rootAddress)) {
        throw new Error(`Invalid wallet address: ${ params.rootAddress }`);
      }

      const accountDataUrl = `${ this.getHorizonUrl() }/accounts/${ params.rootAddress }`;
      const destinationUrl = `${ this.getHorizonUrl() }/accounts/${ params.recoveryDestination }`;

      let accountData;
      try {
        accountData = yield request.get(accountDataUrl).result();
      } catch (e) {
        throw new Error('Unable to reach the Stellar network via Horizon.');
      }

      // Now check if the destination account is empty or not
      let unfundedDestination = false;
      try {
        yield request.get(destinationUrl);
      } catch (e) {
        if (e.status === 404) {
          // If the destination account does not yet exist, horizon responds with 404
          unfundedDestination = true;
        }
      }

      if (!accountData.sequence || !accountData.balances) {
        throw new Error('Horizon server error - unable to retrieve sequence ID or account balance');
      }

      const account = new stellar.Account(params.rootAddress, accountData.sequence);

      // Stellar supports multiple assets on chain, we're only interested in the balances entry whose type is "native" (XLM)
      const nativeBalanceInfo = accountData.balances.find(assetBalance => assetBalance['asset_type'] === 'native');

      if (!nativeBalanceInfo) {
        throw new Error('Provided wallet has a balance of 0 XLM, recovery aborted');
      }

      const walletBalance = this.bigUnitsToBaseUnits(nativeBalanceInfo.balance);
      const minimumReserve = yield this.getMinimumReserve();
      const baseTxFee = yield this.getBaseTransactionFee();
      const recoveryAmount = walletBalance - minimumReserve - baseTxFee;
      const formattedRecoveryAmount = (this.baseUnitsToBigUnits(recoveryAmount)).toString();

      let txBuilder = new stellar.TransactionBuilder(account);
      let operation;
      if (unfundedDestination) { // In this case, we need to create the account
        operation = stellar.Operation.createAccount({
          destination: params.recoveryDestination,
          startingBalance: formattedRecoveryAmount
        });
      } else { // Otherwise if the account already exists, we do a normal send
        operation = stellar.Operation.payment({
          destination: params.recoveryDestination,
          asset: stellar.Asset.native(),
          amount: formattedRecoveryAmount
        });
      }
      txBuilder = txBuilder.addOperation(operation).build();

      if (!isUnsignedSweep) {
        txBuilder.sign(userKey);
      }

      if (!isKrsRecovery && !isUnsignedSweep) {
        txBuilder.sign(backupKey);
      }

      const transaction: any = {
        tx: txBuilder.toEnvelope().toXDR('base64'),
        recoveryAmount
      };

      if (isKrsRecovery) {
        transaction.backupKey = params.backupKey;
        transaction.coin = this.getChain();
      }

      return transaction;
    }).call(this);
开发者ID:BitGo,项目名称:BitGoJS,代码行数:85,代码来源:xlm.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript stellar-sdk.StellarTomlResolver类代码示例发布时间:2022-05-25
下一篇:
TypeScript stellar-sdk.Memo类代码示例发布时间: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