Skip to content

Commit 3137a37

Browse files
committed
[FAB-10049] Change context to pointer
It is more idiomatic in golang to use a pointer instance to pass around a collection of runtime information. This change set changes the context to be initialized as a pointer Change-Id: I146df8918321578c10ed158109a3d031fbc2d516 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 1d4ffbe commit 3137a37

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

core/committer/txvalidator/plugin_validator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewPluginValidator(pm PluginMapper, qec QueryExecutorCreator, deserializer
8989
}
9090
}
9191

92-
func (pv *PluginValidator) ValidateWithPlugin(ctx Context) error {
92+
func (pv *PluginValidator) ValidateWithPlugin(ctx *Context) error {
9393
plugin, err := pv.getOrCreatePlugin(ctx)
9494
if err != nil {
9595
return &validation.ExecutionFailureError{
@@ -105,7 +105,7 @@ func (pv *PluginValidator) ValidateWithPlugin(ctx Context) error {
105105
return err
106106
}
107107

108-
func (pv *PluginValidator) getOrCreatePlugin(ctx Context) (validation.Plugin, error) {
108+
func (pv *PluginValidator) getOrCreatePlugin(ctx *Context) (validation.Plugin, error) {
109109
pluginFactory := pv.PluginFactoryByName(PluginName(ctx.VSCCName))
110110
if pluginFactory == nil {
111111
return nil, errors.Errorf("plugin with name %s wasn't found", ctx.VSCCName)

core/committer/txvalidator/plugin_validator_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestValidateWithPlugin(t *testing.T) {
3030
deserializer := &mocks.IdentityDeserializer{}
3131
capabilites := &mocks.Capabilities{}
3232
v := txvalidator.NewPluginValidator(pm, qec, deserializer, capabilites)
33-
ctx := txvalidator.Context{
33+
ctx := &txvalidator.Context{
3434
Namespace: "mycc",
3535
VSCCName: "vscc",
3636
}
@@ -99,7 +99,7 @@ func TestSamplePlugin(t *testing.T) {
9999

100100
v := txvalidator.NewPluginValidator(pm, qec, deserializer, capabilites)
101101
acceptAllPolicyBytes, _ := proto.Marshal(cauthdsl.AcceptAllPolicy)
102-
ctx := txvalidator.Context{
102+
ctx := &txvalidator.Context{
103103
Namespace: "mycc",
104104
VSCCName: "vscc",
105105
Policy: acceptAllPolicyBytes,

core/committer/txvalidator/vscc_validator.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (v *VsccValidatorImpl) VSCCValidateTx(seq int, payload *common.Payload, env
193193
}
194194

195195
// do VSCC validation
196-
ctx := Context{
196+
ctx := &Context{
197197
Seq: seq,
198198
Envelope: envBytes,
199199
Block: block,
@@ -234,7 +234,7 @@ func (v *VsccValidatorImpl) VSCCValidateTx(seq int, payload *common.Payload, env
234234
// currently, VSCC does custom validation for LSCC only; if an hlf
235235
// user creates a new system chaincode which is invokable from the outside
236236
// they have to modify VSCC to provide appropriate validation
237-
ctx := Context{
237+
ctx := &Context{
238238
Seq: seq,
239239
Envelope: envBytes,
240240
Block: block,
@@ -257,7 +257,7 @@ func (v *VsccValidatorImpl) VSCCValidateTx(seq int, payload *common.Payload, env
257257
return nil, peer.TxValidationCode_VALID
258258
}
259259

260-
func (v *VsccValidatorImpl) VSCCValidateTxForCC(ctx Context) error {
260+
func (v *VsccValidatorImpl) VSCCValidateTxForCC(ctx *Context) error {
261261
logger.Info("Validating", ctx, "with plugin")
262262
err := v.pluginValidator.ValidateWithPlugin(ctx)
263263
if err == nil {

0 commit comments

Comments
 (0)