Hyperledger fabric 如何让参与者/组织进入Converctor控制器?
我想在控制器内获得参与者模型,但我只有身份/指纹。。。。Hyperledger fabric 如何让参与者/组织进入Converctor控制器?,hyperledger-fabric,convector,Hyperledger Fabric,Convector,我想在控制器内获得参与者模型,但我只有身份/指纹。。。。 问题是如何获得参与者模型?答案是将身份/指纹与富couchdb查询结合使用 内部控制器使用此。发送者获取指纹exB5:38:A3:84:02:D1:EE:2B:CD:25:27:66:C0:F6:9E:4F:91:16:21:EE 接下来,首先创建worldstate查询,并在fauxton中进行测试 质疑 完成查询 现在创建一个utils.ts以在控制器中共享,如 packages/person cc/src/utils.ts impo
问题是如何获得参与者模型?答案是将身份/指纹与富couchdb查询结合使用 内部控制器使用此。发送者获取指纹ex
B5:38:A3:84:02:D1:EE:2B:CD:25:27:66:C0:F6:9E:4F:91:16:21:EE
接下来,首先创建worldstate查询,并在fauxton中进行测试
质疑
完成查询
现在创建一个utils.ts以在控制器中共享,如
packages/person cc/src/utils.ts
import { appConstants as c } from '@convector-rest-sample/common';
import * as bcrypt from 'bcrypt';
import { Participant } from 'participant-cc';
const bcryptSaltRounds: number = 10;
export const hashPassword = (password: string): string => {
return bcrypt.hashSync(password, bcryptSaltRounds);
};
/**
* get Participant by Identity/Fingerprint
*/
export const getParticipantByIdentity = async (fingerprint: string): Promise<Participant> => {
const participant: Participant | Participant[] = await Participant.query(Participant, {
selector: {
type: c.CONVECTOR_MODEL_PATH_PARTICIPANT,
identities: {
$elemMatch: {
fingerprint,
status: true
}
}
}
});
if (!!participant && !participant[0].id) {
throw new Error('Cant find a participant with that fingerprint');
}
return participant[0];
}
检查couchdb
{
"_id": "1-100-100",
"_rev": "1-2b08d163d01dcfa5b9e9dc31bcc3b50c",
"email": "pete.doe@example.com",
"firstname": "Pete",
"id": "1-100-103",
"lastname": "Doe",
"participant": {
"id": "gov",
"identities": [
{
"fingerprint": "B5:38:A3:84:02:D1:EE:2B:CD:25:27:66:C0:F6:9E:4F:91:16:21:EE",
"status": true
}
],
"msp": "org1MSP",
"name": "Big Government",
"type": "io.worldsibu.examples.participant"
},
"password": "$2b$10$IYsgUSb/RA6zr4tT3u10HugCrxJH2loLsVUKjTkTiAAj3yewnR2SO",
"roles": [
"USER"
],
"type": "io.worldsibu.examples.person",
"username": "peter",
"~version": "\u0000CgMBDgA="
}
完成
...
import { getParticipantByIdentity, hashPassword } from './utils';
@Controller('person')
export class PersonController extends ConvectorController<ChaincodeTx> {
@Invokable()
public async create(
@Param(Person)
person: Person
) {
// get host participant from fingerprint
const participant: Participant = await getParticipantByIdentity(this.sender);
if (!!participant && !participant.id) {
throw new Error('There is no participant with that identity');
}
...
npx hurl invoke $CC person_create "{\"id\":\"1-100-100\",\"firstname\":\"Pete\",\"lastname\":\"Doe\",\"username\":\"peter\",\"password\":\"12345678\",\"email\":\"pete.doe@example.com\"}" -u admin
{
"_id": "1-100-100",
"_rev": "1-2b08d163d01dcfa5b9e9dc31bcc3b50c",
"email": "pete.doe@example.com",
"firstname": "Pete",
"id": "1-100-103",
"lastname": "Doe",
"participant": {
"id": "gov",
"identities": [
{
"fingerprint": "B5:38:A3:84:02:D1:EE:2B:CD:25:27:66:C0:F6:9E:4F:91:16:21:EE",
"status": true
}
],
"msp": "org1MSP",
"name": "Big Government",
"type": "io.worldsibu.examples.participant"
},
"password": "$2b$10$IYsgUSb/RA6zr4tT3u10HugCrxJH2loLsVUKjTkTiAAj3yewnR2SO",
"roles": [
"USER"
],
"type": "io.worldsibu.examples.person",
"username": "peter",
"~version": "\u0000CgMBDgA="
}