當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript web3-utils._類代碼示例

本文整理匯總了TypeScript中web3-utils._的典型用法代碼示例。如果您正苦於以下問題:TypeScript _類的具體用法?TypeScript _怎麽用?TypeScript _使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了_類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: sendAsync

  public sendAsync(payload: any, callback: any) {

    if (!ThorAPIMapping[payload.method]) {
      return callback(new Error("Method not supported!"), {
        id: payload.id || 0,
        jsonrpc: payload.jsonrpc || "2.0",
        result: null,
      });
    }
    let ret = ThorAPIMapping[payload.method].ret;
    // non-objects does't need isThorified property since thorify just overwritten 3 formatters
    // which all accept object as input
    if (web3Utils._.isObject(ret)) {
      // tricks for fast deep copy since I defined ThorAPIMapping
       ret = JSON.parse(JSON.stringify(ret));
       Object.defineProperty(ret, "reqBody", { get: () => payload, set: () => null });
       Object.defineProperty(ret, "isThorified", { get: () => true, set: () => null });
    }
    if (web3Utils._.isArray(ret)) {
      ret = ret.map((i) => {
        i = JSON.parse(JSON.stringify(i));
        Object.defineProperty(i, "reqBody", { get: () => payload, set: () => null });
        Object.defineProperty(i, "isThorified", { get: () => true, set: () => null });
        return i;
      });
    }
    callback(null, {
      id: payload.id || 0,
      jsonrpc: payload.jsonrpc || "2.0",
      result: ret,
    });
  }
開發者ID:littycoin,項目名稱:thorify,代碼行數:32,代碼來源:fake-provider.ts

示例2: function

export const mustToBN = function(value: any) {
  if (web3Utils._.isNull(value) || web3Utils._.isUndefined(value)) {
    throw new Error("input can't be null or undefined");
  }

  const num = web3Utils.toBN(value);
  return num.abs();
};
開發者ID:littycoin,項目名稱:thorify,代碼行數:8,代碼來源:formatters.ts

示例3: callback

    request.onreadystatechange = () => {
      if (request.readyState === 4) {
        if (request.status !== 200) {
          return callback(new Error("[thorify-provider-http] Invalid response code from provider: " + request.status + (request.responseText ? ", response: " + request.responseText : "")), {
            id: payload.id || 0,
            jsonrpc: payload.jsonrpc || "2.0",
            result: null,
          });
        }
        let result = request.responseText;
        let error = null;

        try {
          result = JSON.parse(result);
        } catch (e) {
          error = invalidResponseError(e);
          return callback(error, {
            id: payload.id || 0,
            jsonrpc: payload.jsonrpc || "2.0",
            result: null,
          });
        }

        debug("result: %O", result);
        result = preparation.ResFormatter(result);

        // tricks for compatible with original web3 instance
        // non-objects or non-arrays does't need isThorified property since thorify just overwritten 3 formatters
        // which all accept object as input
        if (web3Utils._.isObject(result) && !web3Utils._.isArray(result)) {
          Object.defineProperty(result, "isThorified", { get: () => true});
        }
        if (web3Utils._.isArray(result)) {
          result = result.map((item: any) => {
            Object.defineProperty(item, "isThorified", { get: () => true});
            return item;
          });
        }
        callback(error, {
          id: payload.id || 0,
          jsonrpc: payload.jsonrpc || "2.0",
          result,
        });
      }
    };
開發者ID:littycoin,項目名稱:thorify,代碼行數:45,代碼來源:http-provider.ts

示例4: recover

  proto.recover = function recover(message: any, signature: string, preFixed: boolean) {
    const args = [].slice.apply(arguments);

    if (web3Utils._.isObject(message)) {
      return this.recover(message.messageHash, message.signature, true);
    }

    if (!preFixed) {
      message = this.hashMessage(message);
    }

    const hexBuffer = Buffer.from(utils.sanitizeHex(message), "hex");
    const signatureBuffer = Buffer.from(utils.sanitizeHex(signature), "hex");
    return utils.recover(hexBuffer, signatureBuffer);
  };
開發者ID:littycoin,項目名稱:thorify,代碼行數:15,代碼來源:accounts.ts


注:本文中的web3-utils._類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。