具有自定义 IBM Cloudant 钱包的 Hyperledger Composer 失败 - 实体太大
Hyperledger Composer with Custom IBM Cloudant Wallet Fails - Entity too Large
我正在创建一个 nodejs 服务器,我在其中添加参与者并在云钱包上创建卡片。根据我从使用 composer 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 } } }
IBM Cloud 上的所有 Cloudant 版本都规定了 1 兆的最大文档大小。没有办法解决这个问题,并且适用于免费和付费版本。参见 https://console.bluemix.net/docs/services/Cloudant/api/document.html#documents
Cloudant 的高效数据架构通常会使用几千字节的文档。
我正在创建一个 nodejs 服务器,我在其中添加参与者并在云钱包上创建卡片。根据我从使用 composer 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 } } }
IBM Cloud 上的所有 Cloudant 版本都规定了 1 兆的最大文档大小。没有办法解决这个问题,并且适用于免费和付费版本。参见 https://console.bluemix.net/docs/services/Cloudant/api/document.html#documents
Cloudant 的高效数据架构通常会使用几千字节的文档。