Git Product home page Git Product logo

Comments (3)

shohu avatar shohu commented on August 29, 2024

Channel.js

/**
 * Send signed transaction proposal to peer
 *
 * @param {SignedProposal} request signed endorse transaction proposal, this signed
 * proposal would be send to peer directly.
 * @param {number} timeout the timeout setting passed on sendSignedProposal
 */
async sendSignedProposal(request, timeout) {
  return Channel.sendSignedProposal(request, timeout);
}

/**
 * Send signed transaction proposal to peer
 *
 * @param {SignedProposal} request signed endorse transaction proposal, this signed
 * proposal would be send to peer directly.
 * @param {number} timeout the timeout setting passed on sendSignedProposal
 */
static async sendSignedProposal(request, timeout) {
  const responses = await client_utils.sendPeersProposal(request.targets, request.signedProposal, timeout);
  return responses;
}

client-utils.js

/*
 * This function will return one Promise when sending a proposal to many peers
 */
module.exports.sendPeersProposal = async (peers, proposal, timeout) => {
	let targets = peers;
	if (!Array.isArray(peers)) {
		targets = [peers];
	}
	// create array of promises mapping peers array to peer parameter
	// settle all the promises and return array of responses
	const promises = targets.map(async (peer) => {
		return peer.sendProposal(proposal, timeout);
	});
	const responses = [];
	const results = await settle(promises);
	results.forEach((result) => {
		if (result.isFulfilled()) {
			logger.debug(`sendPeersProposal - Promise is fulfilled: ${result.value()}`);
			responses.push(result.value());
		} else {
			logger.debug(`sendPeersProposal - Promise is rejected: ${result.reason()}`);
			responses.push(result.reason());
		}
	});
	return responses;
};

from estate-sample.

shohu avatar shohu commented on August 29, 2024

sendPeersProposal は、どうも fabcar の queryByChaincode でも使われているため
offlineの時と、onlineの時で何がちがっているか調べる。

responseが変わる意味がわかるかもしれない

log挿入場所

module.exports.sendPeersProposal = async (peers, proposal, timeout) => {
	let targets = peers;
	if (!Array.isArray(peers)) {
		targets = [peers];
	}
	// create array of promises mapping peers array to peer parameter
	// settle all the promises and return array of responses
	const promises = targets.map(async (peer) => {
		return peer.sendProposal(proposal, timeout);
	});
	const responses = [];
	const results = await settle(promises);
	results.forEach((result) => {
		if (result.isFulfilled()) {
			logger.debug(`sendPeersProposal - Promise is fulfilled: ${result.value()}`);
			responses.push(result.value());
		} else {
			logger.debug(`sendPeersProposal - Promise is rejected: ${result.reason()}`);
			responses.push(result.reason());
		}
	});
	console.log('====sendPeersProposal==== responses', responses);
	console.log('====sendPeersProposal==== responses.response', responses[0].response.payload.toString());
	return responses;
};

fabcar online

[ { version: 1,
    timestamp: null,
    response:
     { status: 200,
       message: '',
       payload: <Buffer 22 5b 7b 5c 22 4b 65 79 5c 22 3a 5c 22 43 41 52 30 5c 22 2c 5c 22 52 65 63 6f 72 64 5c 22 3a 7b 5c 22 63 6f 6c 6f 72 5c 22 3a 5c 22 62 6c 75 65 5c 22 ... > },
    payload: <Buffer 0a 20 da 35 77 f8 75 b6 7b 7a fb 50 b2 e0 62 c9 91 c1 d7 ef eb ef da 09 40 8e 66 83 74 fa 04 af 61 53 12 8c 0d 0a c1 01 12 a6 01 0a 06 66 61 62 63 61 ... >,
    endorsement:
     { endorser: <Buffer 0a 07 4f 72 67 31 4d 53 50 12 aa 06 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 43 4b 44 43 43 41 63 ... >,
       signature: <Buffer 30 45 02 21 00 83 42 02 fe b0 27 45 a9 0b 1d b3 4a ed 75 d2 fc d2 12 49 e6 a3 23 ae 9d e5 66 1c 6e 60 2c 86 27 02 20 75 ba 17 b5 b4 ff 45 4f 6e 12 2c ... > },
    peer:
     { url: 'grpcs://localhost:7051',
       name: 'localhost:7051',
       options: [Object] } } ]
Query has completed, checking results

fabcar offline

[ { version: 1,
    timestamp: null,
    response:
     { status: 200,
       message: '',
       payload: <Buffer 22 5b 7b 5c 22 4b 65 79 5c 22 3a 5c 22 43 41 52 30 5c 22 2c 5c 22 52 65 63 6f 72 64 5c 22 3a 7b 5c 22 63 6f 6c 6f 72 5c 22 3a 5c 22 62 6c 75 65 5c 22 ... > },
    payload: <Buffer 0a 20 55 37 f5 fa c7 ce 0f 83 bf 82 45 a6 c4 22 c9 b9 e7 65 a6 c2 41 0a 04 60 72 ed e5 14 ca 4c 0b b2 12 8c 0d 0a c1 01 12 a6 01 0a 06 66 61 62 63 61 ... >,
    endorsement:
     { endorser: <Buffer 0a 07 4f 72 67 31 4d 53 50 12 aa 06 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 43 4b 44 43 43 41 63 ... >,
       signature: <Buffer 30 44 02 20 79 cd 4e 5d 79 cc 64 9a 5e 7b d6 96 a9 6f 01 21 0c 8d e3 54 16 1b a1 f0 38 61 d2 aa 7c 94 fb 0f 02 20 58 e1 63 66 8d 20 b8 86 d1 08 5b 5d ... > },
    peer:
     { url: 'grpcs://localhost:7051',
       name: 'localhost:7051',
       options: [Object] } } ]

とおもったら、いっしょのが返ってきたっぽい?
sendPeersProposal の段階ではデータ返ってきているが、
sendSignedTransaction の responseはちゃんと返ってきていないのは、、、なぜz?

以下場所で 
==== sendSignedProposal === Promise { }
になってしまう。これが原因。

	async sendSignedProposal(request, timeout) {
		const responses = Channel.sendSignedProposal(request, timeout);
		console.log('==== sendSignedProposal ===', responses);
		// console.log('1====sendSignedProposal==== responses.response', responses[0].response.payload.toString());
		return responses;
	}

from estate-sample.

shohu avatar shohu commented on August 29, 2024

と、色々書いたが以下のメソッドのresponseで拾えていた 😓

  const proposalResponses = await channel.sendSignedProposal(sendSignedProposalReq)

from estate-sample.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.