带有自定义IBM Cloudant Wallet的Hyperledger Composer失败-实体太大

时间:2018-11-10 22:12:01

标签: hyperledger-fabric hyperledger-composer cloudant

我正在创建一个nodejs服务器,在其中添加参与者并在云钱包上创建卡。从与作曲家sdk一起玩耍中学到的知识,我最终创建了一个函数,该函数可以获取参与者的详细信息,然后发布身份,然后在cloudant上创建卡。直到今天,这种方法仍然运行良好。

突然我收到413-尝试导入卡时实体太大。

有什么建议吗?

const BusinessNetworkConnection = require("composer-client")
  .BusinessNetworkConnection;
const NetworkCardStoreManager = require("composer-common")
  .NetworkCardStoreManager;

const IdCard = require("composer-common").IdCard;

const connectionProfile = JSON.parse(
  JSON.stringify(require("./connection-profile.json"))
);

const walletType = {
  type: "@ampretia/composer-wallet-cloudant",
  options: {
    database: "composer-wallets",
    apikey: "",
    host: "",
    iam_apikey_description: "",
    iam_apikey_name: "",
    iam_serviceid_crn: "",
    password: "",
    port: ,
    url: "",
    username: ""
  }
};

const AdminConnection = require("composer-admin").AdminConnection;

const cardStore = NetworkCardStoreManager.getCardStore(walletType);

const bnConnection = new BusinessNetworkConnection({ cardStore });

const adminConnection = new AdminConnection({ cardStore });


const addParticipantAndIssueIdentity = userDetails => {
  return new Promise(async (resolve, reject) => {
    try {
      await adminConnection.connect("admin@test.com");

      const definition = await bnConnection.connect(
        "admin@test.com"
      );

      const participantRegistry = await bnConnection.getParticipantRegistry(
        `org.test.bna.${userDetails.role}`
      );
      const factory = definition.getFactory();
      let participant = factory.newResource(
        "org.test.bna",
        `${userDetails.role}`,
        `${userDetails.uid}`
      );
      participant.email = userDetails.email;
      participant.firstName = userDetails.firstName;
      participant.lastName = userDetails.lastName;
      await participantRegistry.add(participant);
      const returnedCard = await bnConnection.issueIdentity(
        `org.test.bna.${userDetails.role}#${userDetails.uid}`,
        `${userDetails.uid}`
      );

      const metadata = {
        userName: returnedCard.userID,
        version: 1,
        enrollmentSecret: returnedCard.userSecret,
        businessNetwork: "test"
      };

      const idCard = new IdCard(metadata, connectionProfile);

      console.log("Importing Card 1");
      await adminConnection.importCard(
        `${userDetails.uid}@test`,
        idCard
      ); <----- This call is failing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      console.log("Request Identity");
      const result = await adminConnection.requestIdentity(
        `${userDetails.uid}@test`,
        returnedCard.userID,
        returnedCard.enrollmentSecret
      );

      idCard.setCredentials({
        ...result,
        privateKey: result.key
      });

      console.log("Importing Card 2");
      await adminConnection.importCard(
        `${userDetails.uid}@test`,
        idCard
      );

      console.log("Exporting Card");
      await adminConnection.exportCard(
        `${userDetails.uid}@test`
      );
      resolve(true);
    } catch (error) {
      console.log(error);
      reject(error);
    }
  });
};

更新:

我在下面添加了错误日志:

{ Error: Failed to save card: testCard@test
    at card.toArchive.then.catch (/node_modules/composer-common/lib/cardstore/walletbackedcardstore.js:100:31)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  cause:
   { Error: 413 Request Entity Too Large
    at Object.clientCallback (/node_modules/@cloudant/cloudant/lib/client.js:213:20)
    at Request._callback (/node_modules/@cloudant/cloudant/lib/clientutils.js:154:11)
    at Request.self.callback (/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.self._source.emit (/node_modules/@cloudant/cloudant/lib/eventrelay.js:78:21)
    at Request.<anonymous> (/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at Request.self._source.emit (/node_modules/@cloudant/cloudant/lib/eventrelay.js:78:21)
     _response:
      IncomingMessage {
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        socket: [Object],
        connection: [Object],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        upgrade: false,
        url: '',
        method: null,
        statusCode: 413,
        statusMessage: 'Request Entity Too Large',
        client: [Object],
        _consuming: true,
        _dumped: false,
        req: [Object],
        request: [Object],
        toJSON: [Function: responseToJSON],
        caseless: [Object],
        read: [Function],
        body: '{"error":"document_too_large","reason":"cards"}\n' },
     _data: { error: 'document_too_large', reason: 'cards', statusCode: 413 } } }
{ Error: Failed to save card: pleasework52@airspace-blockchain-company
    at card.toArchive.then.catch (/node_modules/composer-common/lib/cardstore/walletbackedcardstore.js:100:31)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  cause:
   { Error: 413 Request Entity Too Large
    at Object.clientCallback (/node_modules/@cloudant/cloudant/lib/client.js:213:20)
    at Request._callback (/node_modules/@cloudant/cloudant/lib/clientutils.js:154:11)
    at Request.self.callback (/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.self._source.emit (/node_modules/@cloudant/cloudant/lib/eventrelay.js:78:21)
    at Request.<anonymous> (/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at Request.self._source.emit (/node_modules/@cloudant/cloudant/lib/eventrelay.js:78:21)
     _response:
      IncomingMessage {
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        socket: [Object],
        connection: [Object],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        upgrade: false,
        url: '',
        method: null,
        statusCode: 413,
        statusMessage: 'Request Entity Too Large',
        client: [Object],
        _consuming: true,
        _dumped: false,
        req: [Object],
        request: [Object],
        toJSON: [Function: responseToJSON],
        caseless: [Object],
        read: [Function],
        body: '{"error":"document_too_large","reason":"cards"}\n' },
     _data: { error: 'document_too_large', reason: 'cards', statusCode: 413 } } }

1 个答案:

答案 0 :(得分:0)

IBM Cloud上所有类型的Cloudant的最大文档大小为1兆。无法解决此问题,并且适用于免费和付费版本。参见https://console.bluemix.net/docs/services/Cloudant/api/document.html#documents

Cloudant的高效数据架构通常会使用几千字节的文档。