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

TypeScript bluebird.coroutine函数代码示例

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

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



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

示例1: describe

describe('Virtual Token:', function() {
  let bitgo;

  before(function() {
    bitgo = new TestV2BitGo({ env: 'test' });
    bitgo.initializeTestVars();
  });

  it('should not instantiate coin interface before loading client constants', function() {
    (() => bitgo.coin('mycrappytoken')).should.throw('Coin or token type mycrappytoken not supported or not compiled');
  });

  it('should wait for client constants before instantiating coin', Promise.coroutine(function *() {
    const promise = bitgo.token('terc');
    should(promise).be.instanceOf(Promise);
    const erc = yield promise;
    const BaseCoin = require('../../../../src/v2/baseCoin');
    erc.should.be.instanceOf(BaseCoin);
    erc.type.should.equal('terc');
    erc.tokenContractAddress.should.equal('0x945ac907cf021a6bcd07852bb3b8c087051706a9');
  }));

});
开发者ID:BitGo,项目名称:BitGoJS,代码行数:23,代码来源:token.ts


示例2: coroutine1

            args.push(resolve, reject);
            originalMethod.apply(this, args);
        });
    };
}

obj = Bluebird.promisifyAll(obj, {
	suffix: "",
	filter: defaultFilter,
	promisifier: DOMPromisifier
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

const generator1 = function*(a: number, b: string) { return "string"; };
const coroutine1 = Bluebird.coroutine<string, number, string>(generator1);
strProm = coroutine1(5, "foo");

const generator2 = function*(a: number, b: string) {
	yield foo;
	return bar;
};
const coroutine2 = Bluebird.coroutine<Bar, number, string>(generator2);
barProm = coroutine2(5, "foo");

const coroutineCustomYield = Bluebird.coroutine(generator1, { yieldHandler: (value) => "whatever" });
/*
 barProm = Bluebird.spawn<number>(f);
 */
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:30,代码来源:bluebird-tests.ts


示例3: describe

  describe('Update Password', function() {
    let bitgo;
    let keychains;
    let correctPassword;

    before(co(function *beforeUpdatePassword() {
      bitgo = new TestBitGo({ env: 'test' });
      bitgo.initializeTestVars();
      keychains = bitgo.keychains();
      const loginPasswords = yield bitgo.authenticateChangePWTestUser(bitgo.testUserOTP());
      correctPassword = loginPasswords.password;
      yield bitgo.unlock({ otp: bitgo.testUserOTP() });
    }));

    it('successful update the password for all v1 keychains that are encrypted with the old password', co(function *itUpdatePassword() {
      const newPassword = 'newPassword';
      const result = yield keychains.updatePassword({ oldPassword: correctPassword, newPassword });
      _.forOwn(result.keychains, function(encryptedXprv, xpub) {
        xpub.should.startWith('xpub');
        try {
          const decryptedPrv = bitgo.decrypt({ input: encryptedXprv, password: newPassword });
          decryptedPrv.should.startWith('xprv');
        } catch (e) {
          // the decryption didn't work because of the wrong password, this is one of the keychains that wasn't
          // encrypted with the old password
          e.message.should.startWith('password error');
        }
      });
      result.should.hasOwnProperty('version');
    }));
  });
开发者ID:BitGo,项目名称:BitGoJS,代码行数:31,代码来源:keychains.ts


示例4: co

Wallets.prototype.resendShareInvite = function(params, callback) {
  return co(function *() {
    params = params || {};
    common.validateParams(params, ['walletShareId'], [], callback);

    const urlParts = params.walletShareId + '/resendemail';
    return this.bitgo.post(this.bitgo.url('/walletshare/' + urlParts))
    .result();
  }).call(this).asCallback(callback);
};
开发者ID:BitGo,项目名称:BitGoJS,代码行数:10,代码来源:wallets.ts


示例5: co

  getAddressInfoFromExplorer(addressBase58) {
    return co(function *getAddressInfoFromExplorer() {
      const addrInfo = yield request.get(this.recoveryBlockchainExplorerUrl(`/address/${addressBase58}`)).result();

      addrInfo.txCount = addrInfo.address.total.transaction_count;
      addrInfo.totalBalance = addrInfo.address.total.balance_int;

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


示例6: describe

  describe('Recover Wallet:', () => {

    let coin, bitgo;

    before(() => {
      bitgo = new TestBitGo({ env: 'mock' });
      coin = bitgo.coin('tbtc');
      sinon.stub(coin, 'verifyRecoveryTransaction').resolvesArg(0);
    });

    it('should construct a recovery transaction with segwit unspents', co(function *() {
      const { params, expectedTxHex } = fixtures.recoverBtcSegwitFixtures();
      recoveryNocks.nockBtcSegwitRecovery();
      const tx = yield coin.recover(params);
      const transaction = utxoLib.Transaction.fromHex(tx.transactionHex);
      transaction.ins.length.should.equal(2);
      transaction.outs.length.should.equal(1);
      transaction.outs[0].value.should.equal(57112);
      tx.transactionHex.should.equal(expectedTxHex);
    }));

    it('should construct an unsigned recovery transaction for the offline vault', co(function *() {
      const { params, expectedTxHex } = fixtures.recoverBtcUnsignedFixtures();
      recoveryNocks.nockBtcUnsignedRecovery();
      const txPrebuild = yield coin.recover(params);
      txPrebuild.txHex.should.equal(expectedTxHex);
      txPrebuild.should.have.property('feeInfo');
      txPrebuild.coin.should.equal('tbtc');
      txPrebuild.txInfo.unspents.length.should.equal(2);
    }));

    after(function() {
      nock.cleanAll();
      coin.verifyRecoveryTransaction.restore();
    });

  });
开发者ID:BitGo,项目名称:BitGoJS,代码行数:37,代码来源:abstractUtxoCoin.ts


示例7: verifyRecoveryTransaction

  public verifyRecoveryTransaction(txInfo) {
    return co(function *verifyRecoveryTransaction() {
      const decodedTx = yield request.post(this.recoveryBlockchainExplorerUrl(`/decodetx`))
      .send({ hex: txInfo.transactionHex })
      .result();

      const transactionDetails = decodedTx.transaction;

      const tx = bitcoin.Transaction.fromHex(txInfo.transactionHex, this.network);
      if (transactionDetails.TxId !== tx.getId()) {
        console.log(transactionDetails.TxId);
        console.log(tx.getId());
        throw new Error('inconsistent recovery transaction id');
      }

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


示例8: function

describe('V2 Trading', function() {
  const microservicesUri = 'https://bitgo-microservices.example';
  let bitgo;
  let basecoin;
  let wallet;
  let trading;
  let bgUrl;

  before(co(function *() {
    bitgo = new TestV2BitGo({ env: 'mock', microservicesUri });
    bitgo.initializeTestVars();
    basecoin = bitgo.coin('ofc');
    basecoin.keychains();

    const walletData = {
      id: 'walletId',
      coin: 'tbtc',
      keys: [
        'keyid'
      ]
    };

    wallet = new Wallet(bitgo, basecoin, walletData);
    trading = wallet.trading();
    bgUrl = common.Environments[bitgo.getEnv()].uri;
  }));

  it('should create and sign a trade payload', co(function *() {
    const xprv = 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR';
    const xpub = 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX';

    const msScope = nock(microservicesUri)
    .post('/api/trade/v1/payload')
    .reply(200, {
      payload: JSON.stringify({
        walletId: 'walletId',
        currency: 'tbtc',
        amount: '100000000',
        otherParties: ['test_counter_party_1'],
        nonce: Date.now()
      })
    });
    const platformScope = nock(bgUrl)
    .get('/api/v2/ofc/key/keyid')
    .reply(200, {
      pub: xpub,
      encryptedPrv: bitgo.encrypt({ input: xprv, password: TestV2BitGo.OFC_TEST_PASSWORD })
    });

    const { payload, signature } = yield trading.signTradePayload({
      currency: 'tbtc',
      amount: '100000000',
      otherParties: ['test_counterparty_1'],
      walletPassphrase: TestV2BitGo.OFC_TEST_PASSWORD
    });

    should.exist(payload);
    // The payload should be a valid JSON object
    // NOTE: we shouldn't do any more validation than this, as the schema is subject to change often
    (() => { JSON.parse(payload); }).should.not.throw();

    should.exist(signature);
    // signature should be a hex string
    signature.should.match(/^[0-9a-f]+$/);

    const address = HDNode.fromBase58(xpub).getAddress();

    bitcoinMessage.verify(payload, address, Buffer.from(signature, 'hex')).should.be.True();

    msScope.isDone().should.be.True();
    platformScope.isDone().should.be.True();
  }));
});
开发者ID:BitGo,项目名称:BitGoJS,代码行数:73,代码来源:trading.ts


示例9: createServer

  describe('server initialization', function() {

    it('should require NODE_ENV to be production when running against prod env', function() {
      const envStub = sinon.stub(process, 'env').value({ NODE_ENV: 'production' });

      try {
        (() => expressApp({
          env: 'prod',
          bind: 'localhost'
        })).should.not.throw();

        process.env.NODE_ENV = 'dev';
        (() => expressApp({
          env: 'prod',
          bind: 'localhost'
        })).should.throw(NodeEnvironmentError);
      } finally {
        envStub.restore();
      }
    });

    it('should disable NODE_ENV check if disableenvcheck argument is given', function() {
      const envStub = sinon.stub(process, 'env').value({ NODE_ENV: 'dev' });

      try {
        (() => expressApp({
          env: 'prod',
          bind: 'localhost',
          disableenvcheck: true
        })).should.not.throw();
      } finally {
        envStub.restore();
      }
    });

    it('should require TLS for prod env when listening on external interfaces', function() {
      const args = {
        env: 'prod',
        bind: '1',
        disableenvcheck: true,
        disablessl: false,
        crtpath: null,
        keypath: null,
      };

      (() => expressApp(args)).should.throw(TlsConfigurationError);

      args.bind = 'localhost';
      (() => expressApp(args)).should.not.throw();

      args.bind = '1';
      args.env = 'test';
      (() => expressApp(args)).should.not.throw();

      args.disablessl = true;
      args.env = 'prod';
      (() => expressApp(args)).should.not.throw();

      delete args.disablessl;
      args.crtpath = '/tmp/cert.pem';
      (() => expressApp(args)).should.throw(TlsConfigurationError);

      delete args.crtpath;
      args.keypath = '/tmp/key.pem';
      (() => expressApp(args)).should.throw(TlsConfigurationError);

    });

    it('should require both keypath and crtpath when using TLS, but TLS is not required', function() {
      const args = {
        env: 'test',
        bind: '1',
        keypath: '/tmp/key.pem',
        crtpath: null,
      };

      (() => expressApp(args)).should.throw(TlsConfigurationError);

      delete args.keypath;
      args.crtpath = '/tmp/cert.pem';

      (() => expressApp(args)).should.throw(TlsConfigurationError);
    });

    it('should create an http server when not using TLS', co(function *() {
      sinon.stub(http, 'createServer');

      const args = {
        env: 'prod',
        bind: 'localhost'
      };

      createServer(args);

      http.createServer.should.be.calledOnce();
      http.createServer.restore();
    }));

    it('should create an https server when using TLS', co(function *() {
      sinon.stub(https, 'createServer');
//.........这里部分代码省略.........
开发者ID:BitGo,项目名称:BitGoJS,代码行数:101,代码来源:bitgoExpress.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript bluebird.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript bluebird.config函数代码示例发布时间: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