Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.

Commit 441c193

Browse files
author
Silas Davis
authored
Merge pull request #1392 from hyperledger/vent-no-blob
[Vent] Add BytesToHex flag to byte32 fields to hex string columns
2 parents 8b0bc7e + 53b7fa6 commit 441c193

11 files changed

+50
-21
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# [Hyperledger Burrow](https://github.com/hyperledger/burrow) Changelog
2+
## [0.30.5] - 2020-07-09
3+
### Added
4+
- [Vent] Add BytesToHex flag on projection field mappings that causes bytes fields (e.g. bytes32) solidity fields to be hex-encoded and mapped to varchar(64) rather than bytea/blob columns in postgres/sqlite
5+
6+
27
## [0.30.4] - 2020-04-05
38
### Added
49
- [Build] Added Helm chart
5-
- [State] Account now has OpcodeBitset field to support upcoming EVM fixes
10+
- [State] Account now has EVMOpcodeBitset field to support upcoming EVM fixes
611

712
### Fixed
813
- [JS] Github actions release of JS lib
@@ -661,6 +666,7 @@ This release marks the start of Eris-DB as the full permissioned blockchain node
661666
- [Blockchain] Fix getBlocks to respect block height cap.
662667

663668

669+
[0.30.5]: https://github.com/hyperledger/burrow/compare/v0.30.4...v0.30.5
664670
[0.30.4]: https://github.com/hyperledger/burrow/compare/v0.30.3...v0.30.4
665671
[0.30.3]: https://github.com/hyperledger/burrow/compare/v0.30.2...v0.30.3
666672
[0.30.2]: https://github.com/hyperledger/burrow/compare/v0.30.1...v0.30.2

NOTES.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
### Added
2-
- [Build] Added Helm chart
3-
- [State] Account now has OpcodeBitset field to support upcoming EVM fixes
4-
5-
### Fixed
6-
- [JS] Github actions release of JS lib
2+
- [Vent] Add BytesToHex flag on projection field mappings that causes bytes fields (e.g. bytes32) solidity fields to be hex-encoded and mapped to varchar(64) rather than bytea/blob columns in postgres/sqlite
73

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ services:
66
- POSTGRES_HOST_AUTH_METHOD=trust
77
ports:
88
- 5432
9-
environment:
10-
- POSTGRES_HOST_AUTH_METHOD=trust
119

1210
burrow:
1311
build: .github

project/history.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ func FullVersion() string {
4747
// To cut a new release add a release to the front of this slice then run the
4848
// release tagging script: ./scripts/tag_release.sh
4949
var History relic.ImmutableHistory = relic.NewHistory("Hyperledger Burrow", "https://github.com/hyperledger/burrow").
50-
MustDeclareReleases("0.30.4 - 2020-04-05",
50+
MustDeclareReleases(
51+
"0.30.5 - 2020-07-09",
52+
`### Added
53+
- [Vent] Add BytesToHex flag on projection field mappings that causes bytes fields (e.g. bytes32) solidity fields to be hex-encoded and mapped to varchar(64) rather than bytea/blob columns in postgres/sqlite
54+
`,
55+
"0.30.4 - 2020-04-05",
5156
`### Added
5257
- [Build] Added Helm chart
5358
- [State] Account now has EVMOpcodeBitset field to support upcoming EVM fixes

vent/service/consumer_postgres_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ func TestPostgresConsumer(t *testing.T) {
111111
t.Logf("latest height: %d, txe height: %d", height, txe.Height)
112112
assert.True(t, height >= txe.Height)
113113
}
114-
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "\\x5472696767657220697421000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`, notifications["meta"])
115-
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "\\x5472696767657220697421000000000000000000000000000000000000000000", "testkey" : "\\x544553545f4556454e5453000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`,
114+
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "5472696767657220697421000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`,
115+
notifications["meta"])
116+
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "5472696767657220697421000000000000000000000000000000000000000000", "testkey" : "\\x544553545f4556454e5453000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`,
116117
notifications["keyed_meta"])
117118
})
118119
})

vent/service/rowbuilder.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hyperledger/burrow/vent/sqlsol"
1414
"github.com/hyperledger/burrow/vent/types"
1515
"github.com/pkg/errors"
16+
"github.com/tmthrgd/go-hex"
1617
)
1718

1819
// buildEventData builds event data from transactions
@@ -50,11 +51,12 @@ func buildEventData(projection *sqlsol.Projection, eventClass *types.EventClass,
5051
}
5152
column, err := projection.GetColumn(eventClass.TableName, fieldMapping.ColumnName)
5253
if err == nil {
53-
if fieldMapping.BytesToString {
54-
if bs, ok := value.(*[]byte); ok {
54+
if bs, ok := value.(*[]byte); ok {
55+
if fieldMapping.BytesToString {
5556
str := sanitiseBytesForString(*bs, logger)
56-
row[column.Name] = interface{}(str)
57-
continue
57+
value = interface{}(str)
58+
} else if fieldMapping.BytesToHex {
59+
value = hex.EncodeUpperToString(*bs)
5860
}
5961
}
6062
row[column.Name] = value

vent/sqlsol/projection.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ func NewProjection(spec types.ProjectionSpec) (*Projection, error) {
120120

121121
i := 0
122122
for _, mapping := range eventClass.FieldMappings {
123-
sqlType, sqlTypeLength, err := getSQLType(mapping.Type, mapping.BytesToString)
123+
var bytesMapping BytesMapping
124+
if mapping.BytesToHex {
125+
bytesMapping = BytesToHex
126+
} else if mapping.BytesToString {
127+
bytesMapping = BytesToString
128+
}
129+
sqlType, sqlTypeLength, err := getSQLType(mapping.Type, bytesMapping)
124130
if err != nil {
125131
return nil, err
126132
}
@@ -220,9 +226,17 @@ func readFile(file string) ([]byte, error) {
220226
return byteValue, nil
221227
}
222228

229+
type BytesMapping int
230+
231+
const (
232+
BytesToBytes = iota
233+
BytesToString
234+
BytesToHex
235+
)
236+
223237
// getSQLType maps event input types with corresponding SQL column types
224238
// takes into account related solidity types info and element indexed or hashed
225-
func getSQLType(evmSignature string, bytesToString bool) (types.SQLColumnType, int, error) {
239+
func getSQLType(evmSignature string, bytesMapping BytesMapping) (types.SQLColumnType, int, error) {
226240
evmSignature = strings.ToLower(evmSignature)
227241
re := regexp.MustCompile("[0-9]+")
228242
typeSize, _ := strconv.Atoi(re.FindString(evmSignature))
@@ -237,9 +251,12 @@ func getSQLType(evmSignature string, bytesToString bool) (types.SQLColumnType, i
237251
// solidity bytes => sql bytes
238252
// bytesToString == true means there is a string in there so => sql varchar
239253
case strings.HasPrefix(evmSignature, types.EventFieldTypeBytes):
240-
if bytesToString {
241-
return types.SQLColumnTypeVarchar, 40, nil
242-
} else {
254+
switch bytesMapping {
255+
case BytesToString:
256+
return types.SQLColumnTypeVarchar, 32, nil
257+
case BytesToHex:
258+
return types.SQLColumnTypeVarchar, 64, nil
259+
default:
243260
return types.SQLColumnTypeByteA, 0, nil
244261
}
245262
// solidity string => sql text

vent/test/sqlsol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func UnknownTypeJSONConfFile(t *testing.T) string {
109109
},
110110
"Fields" ,
111111
"ColumnName" , "ColumnName" : "testname", "Primary" : true},
112-
"description", "ColumnName" : "testdescription", "Primary" : false}
112+
"description", "ColumnName" : "testdescription", "Primary" : false, "BytesToHex": true}
113113
}
114114
}
115115
]`

vent/test/sqlsol_log.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"ColumnName": "testdescription",
2424
"Type": "bytes32",
2525
"Primary": false,
26+
"BytesToHex": true,
2627
"Notify": ["meta", "keyed_meta"]
2728
}
2829
]

vent/test/sqlsol_view.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"ColumnName": "testdescription",
2525
"Type": "bytes32",
2626
"Primary": false,
27+
"BytesToHex": true,
2728
"Notify": ["meta", "keyed_meta"]
2829
}
2930
]

vent/types/event_class.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type EventFieldMapping struct {
7979
Primary bool `json:",omitempty"`
8080
// Whether to convert this event field from bytes32 to string
8181
BytesToString bool `json:",omitempty"`
82+
// Whether to convert this event field from bytes32 to hex-encoded string
83+
BytesToHex bool `json:",omitempty"`
8284
// Notification channels on which submit (via a trigger) a payload that contains this column's new value (upsert) or
8385
// old value (delete). The payload will contain all other values with the same channel set as a JSON object.
8486
Notify []string `json:",omitempty"`

0 commit comments

Comments
 (0)