From c11e8b61b9d8c7e3f3c44da24f24eabadd6fb839 Mon Sep 17 00:00:00 2001 From: codchen Date: Mon, 6 May 2024 15:40:43 +0800 Subject: [PATCH] add sdk.Result decorator --- types/result.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/types/result.go b/types/result.go index d0a7e5263..564ca8114 100644 --- a/types/result.go +++ b/types/result.go @@ -227,6 +227,10 @@ func (r TxResponse) GetTx() Tx { return nil } +type ResultDecorator interface { + DecorateSdkResult(*Result) +} + // WrapServiceResult wraps a result from a protobuf RPC service method call in // a Result object or error. This method takes care of marshaling the res param to // protobuf and attaching any events on the ctx.EventManager() to the Result. @@ -248,8 +252,14 @@ func WrapServiceResult(ctx Context, res proto.Message, err error) (*Result, erro events = evtMgr.ABCIEvents() } - return &Result{ + sdkRes := &Result{ Data: data, Events: events, - }, nil + } + if res != nil { + if decorator, ok := res.(ResultDecorator); ok { + decorator.DecorateSdkResult(sdkRes) + } + } + return sdkRes, nil }