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

Commit

Permalink
Merge pull request #1392 from hyperledger/vent-no-blob
Browse files Browse the repository at this point in the history
[Vent] Add BytesToHex flag to byte32 fields to hex string columns
  • Loading branch information
Silas Davis authored Jul 9, 2020
2 parents 8b0bc7e + 53b7fa6 commit 441c193
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 21 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# [Hyperledger Burrow](https://github.com/hyperledger/burrow) Changelog
## [0.30.5] - 2020-07-09
### Added
- [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


## [0.30.4] - 2020-04-05
### Added
- [Build] Added Helm chart
- [State] Account now has OpcodeBitset field to support upcoming EVM fixes
- [State] Account now has EVMOpcodeBitset field to support upcoming EVM fixes

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


[0.30.5]: https://github.com/hyperledger/burrow/compare/v0.30.4...v0.30.5
[0.30.4]: https://github.com/hyperledger/burrow/compare/v0.30.3...v0.30.4
[0.30.3]: https://github.com/hyperledger/burrow/compare/v0.30.2...v0.30.3
[0.30.2]: https://github.com/hyperledger/burrow/compare/v0.30.1...v0.30.2
Expand Down
6 changes: 1 addition & 5 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
### Added
- [Build] Added Helm chart
- [State] Account now has OpcodeBitset field to support upcoming EVM fixes

### Fixed
- [JS] Github actions release of JS lib
- [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

2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ services:
- POSTGRES_HOST_AUTH_METHOD=trust
ports:
- 5432
environment:
- POSTGRES_HOST_AUTH_METHOD=trust

burrow:
build: .github
Expand Down
7 changes: 6 additions & 1 deletion project/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func FullVersion() string {
// To cut a new release add a release to the front of this slice then run the
// release tagging script: ./scripts/tag_release.sh
var History relic.ImmutableHistory = relic.NewHistory("Hyperledger Burrow", "https://github.com/hyperledger/burrow").
MustDeclareReleases("0.30.4 - 2020-04-05",
MustDeclareReleases(
"0.30.5 - 2020-07-09",
`### Added
- [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
`,
"0.30.4 - 2020-04-05",
`### Added
- [Build] Added Helm chart
- [State] Account now has EVMOpcodeBitset field to support upcoming EVM fixes
Expand Down
5 changes: 3 additions & 2 deletions vent/service/consumer_postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ func TestPostgresConsumer(t *testing.T) {
t.Logf("latest height: %d, txe height: %d", height, txe.Height)
assert.True(t, height >= txe.Height)
}
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "\\x5472696767657220697421000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`, notifications["meta"])
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "\\x5472696767657220697421000000000000000000000000000000000000000000", "testkey" : "\\x544553545f4556454e5453000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`,
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "5472696767657220697421000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`,
notifications["meta"])
assert.Equal(t, `{"_action" : "INSERT", "testdescription" : "5472696767657220697421000000000000000000000000000000000000000000", "testkey" : "\\x544553545f4556454e5453000000000000000000000000000000000000000000", "testname" : "TestTriggerEvent"}`,
notifications["keyed_meta"])
})
})
Expand Down
10 changes: 6 additions & 4 deletions vent/service/rowbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hyperledger/burrow/vent/sqlsol"
"github.com/hyperledger/burrow/vent/types"
"github.com/pkg/errors"
"github.com/tmthrgd/go-hex"
)

// buildEventData builds event data from transactions
Expand Down Expand Up @@ -50,11 +51,12 @@ func buildEventData(projection *sqlsol.Projection, eventClass *types.EventClass,
}
column, err := projection.GetColumn(eventClass.TableName, fieldMapping.ColumnName)
if err == nil {
if fieldMapping.BytesToString {
if bs, ok := value.(*[]byte); ok {
if bs, ok := value.(*[]byte); ok {
if fieldMapping.BytesToString {
str := sanitiseBytesForString(*bs, logger)
row[column.Name] = interface{}(str)
continue
value = interface{}(str)
} else if fieldMapping.BytesToHex {
value = hex.EncodeUpperToString(*bs)
}
}
row[column.Name] = value
Expand Down
27 changes: 22 additions & 5 deletions vent/sqlsol/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ func NewProjection(spec types.ProjectionSpec) (*Projection, error) {

i := 0
for _, mapping := range eventClass.FieldMappings {
sqlType, sqlTypeLength, err := getSQLType(mapping.Type, mapping.BytesToString)
var bytesMapping BytesMapping
if mapping.BytesToHex {
bytesMapping = BytesToHex
} else if mapping.BytesToString {
bytesMapping = BytesToString
}
sqlType, sqlTypeLength, err := getSQLType(mapping.Type, bytesMapping)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -220,9 +226,17 @@ func readFile(file string) ([]byte, error) {
return byteValue, nil
}

type BytesMapping int

const (
BytesToBytes = iota
BytesToString
BytesToHex
)

// getSQLType maps event input types with corresponding SQL column types
// takes into account related solidity types info and element indexed or hashed
func getSQLType(evmSignature string, bytesToString bool) (types.SQLColumnType, int, error) {
func getSQLType(evmSignature string, bytesMapping BytesMapping) (types.SQLColumnType, int, error) {
evmSignature = strings.ToLower(evmSignature)
re := regexp.MustCompile("[0-9]+")
typeSize, _ := strconv.Atoi(re.FindString(evmSignature))
Expand All @@ -237,9 +251,12 @@ func getSQLType(evmSignature string, bytesToString bool) (types.SQLColumnType, i
// solidity bytes => sql bytes
// bytesToString == true means there is a string in there so => sql varchar
case strings.HasPrefix(evmSignature, types.EventFieldTypeBytes):
if bytesToString {
return types.SQLColumnTypeVarchar, 40, nil
} else {
switch bytesMapping {
case BytesToString:
return types.SQLColumnTypeVarchar, 32, nil
case BytesToHex:
return types.SQLColumnTypeVarchar, 64, nil
default:
return types.SQLColumnTypeByteA, 0, nil
}
// solidity string => sql text
Expand Down
2 changes: 1 addition & 1 deletion vent/test/sqlsol.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func UnknownTypeJSONConfFile(t *testing.T) string {
},
"Fields" ,
"ColumnName" , "ColumnName" : "testname", "Primary" : true},
"description", "ColumnName" : "testdescription", "Primary" : false}
"description", "ColumnName" : "testdescription", "Primary" : false, "BytesToHex": true}
}
}
]`
Expand Down
1 change: 1 addition & 0 deletions vent/test/sqlsol_log.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"ColumnName": "testdescription",
"Type": "bytes32",
"Primary": false,
"BytesToHex": true,
"Notify": ["meta", "keyed_meta"]
}
]
Expand Down
1 change: 1 addition & 0 deletions vent/test/sqlsol_view.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"ColumnName": "testdescription",
"Type": "bytes32",
"Primary": false,
"BytesToHex": true,
"Notify": ["meta", "keyed_meta"]
}
]
Expand Down
2 changes: 2 additions & 0 deletions vent/types/event_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type EventFieldMapping struct {
Primary bool `json:",omitempty"`
// Whether to convert this event field from bytes32 to string
BytesToString bool `json:",omitempty"`
// Whether to convert this event field from bytes32 to hex-encoded string
BytesToHex bool `json:",omitempty"`
// Notification channels on which submit (via a trigger) a payload that contains this column's new value (upsert) or
// old value (delete). The payload will contain all other values with the same channel set as a JSON object.
Notify []string `json:",omitempty"`
Expand Down

0 comments on commit 441c193

Please sign in to comment.