fabric-sdk-node icon indicating copy to clipboard operation
fabric-sdk-node copied to clipboard

[Refactor] fabric-common ServiceHandler

Open davidkhala opened this issue 4 years ago • 1 comments

You're correct, I'm sure this could be improved. Perhaps instead of a handler being passed in with the signature:

export class ServiceHandler {
	commit(signedEnvelope: Buffer, request: any): Promise<any>;
	endorse(signedProposal: Buffer, request: any): Promise<any>;
	query(signedProposal: Buffer, request: any): Promise<any>;
}

an appropriate handler function of the form (messageBytes: Buffer, options: any): Promise<any> (although ideally with better typing than this!) could be passed in by subclass overrides of the send. Perhaps then this function could just invoke the handler function and not have to figure out which method to call on the handler based on the subclass type.

Perhaps it would also be useful to have a TargetedHandler implementation for when specific peers are targeted too. Then this method wouldn't need the if (handler) { ... } else if (targets) { ... } else { ... } construct. There could just be a single piece of logic that invokes all handlers the same way.

If you do want to make changes here, that might be something for a follow-up PR.

Originally posted by @bestbeforetoday in https://github.com/hyperledger/fabric-sdk-node/pull/512#discussion_r728229926

davidkhala avatar Oct 20 '21 08:10 davidkhala

Please assign this issue to me

davidkhala avatar Oct 20 '21 08:10 davidkhala

Just as some house-keeping, I am closing this issue as it has been inactive for a long time. Please comment if you want to resume work, although I would recommend investing any client SDK development effort on hyperledger/fabric-gateway instead of here.

bestbeforetoday avatar Feb 28 '23 13:02 bestbeforetoday