Skip to content

Commit

Permalink
Formalize base64 serializer
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
  • Loading branch information
peterbroadhurst committed Oct 20, 2024
1 parent 2aaf316 commit ee4f1b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/abi/outputserialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package abi

import (
"context"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -151,6 +152,10 @@ func HexByteSerializer0xPrefix(b []byte) interface{} {
return "0x" + hex.EncodeToString(b)
}

func Base64ByteSerializer(b []byte) interface{} {
return base64.StdEncoding.EncodeToString(b)
}

func NumericDefaultNameGenerator(idx int) string {
return strconv.FormatInt(int64(idx), 10)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/abi/outputserialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package abi

import (
"context"
"encoding/base64"
"math/big"
"strconv"
"testing"
Expand Down Expand Up @@ -78,9 +77,7 @@ func TestJSONSerializationFormatsTuple(t *testing.T) {
SetIntSerializer(func(i *big.Int) interface{} {
return "0o" + i.Text(8)
}).
SetByteSerializer(func(b []byte) interface{} {
return base64.StdEncoding.EncodeToString(b)
}).
SetByteSerializer(Base64ByteSerializer).
SerializeJSON(v)
assert.NoError(t, err)
assert.JSONEq(t, `[
Expand Down

0 comments on commit ee4f1b4

Please sign in to comment.