Skip to content

Conversation

@nguyer
Copy link
Contributor

@nguyer nguyer commented Jan 20, 2022

This PR introduces JSON Schema into FFIs for describing FFIParams. FFIParams now have a Schema field that encompasses the previously used Type and Details fields.

The JSON Schema library used allows for extensions with custom compilers and validators to be added. So FireFly's JSON Schema for FFIs is a slightly more restrictive version of JSON Schema draft 2020-12 with the following requirements:

  • The type field is always required
  • The list of valid types are:
    • string
    • integer
    • boolean
    • array
    • object

The type field is now only used for telling FireFly the input format of a field when a request is made to FireFly's API to invoke a smart contract.

For more specialized fields such as bytes, the input format would be string and an additional contentEncoding property can be added to the schema to indicate how to treat the contents of that string.

Additionally, blockchain plugins can expose a JSON Schema extension interface specific to that particular blockchain implementation. For example, the Ethereum plugin adds additional requirements (with another meta schema):

  • details field is always required as an object
  • details must contain a property called type that will always be a string
    • The compiler for the Ethereum JSON Schema extension also checks to make sure that the input type and the Ethereum type are a valid pairing
  • An indexed boolean property is optional

@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2022

Codecov Report

Merging #419 (39d7471) into main (00fff72) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #419   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          277       278    +1     
  Lines        14958     14952    -6     
=========================================
- Hits         14958     14952    -6     
Impacted Files Coverage Δ
pkg/fftypes/ffi.go 100.00% <ø> (ø)
internal/blockchain/ethereum/ethereum.go 100.00% <100.00%> (ø)
internal/blockchain/ethereum/eventstream.go 100.00% <100.00%> (ø)
...nternal/blockchain/ethereum/ffi_param_validator.go 100.00% <100.00%> (ø)
internal/blockchain/fabric/fabric.go 100.00% <100.00%> (ø)
internal/contracts/ffi_param_validator.go 100.00% <100.00%> (ø)
internal/contracts/manager.go 100.00% <100.00%> (ø)
internal/data/json_validator.go 100.00% <100.00%> (ø)
internal/oapiffi/ffi2swagger.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00fff72...39d7471. Read the comment docs.

@nguyer nguyer marked this pull request as ready for review January 21, 2022 16:12
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder why a few refs to this old library stuck around. Transitive dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not sure

return true
}
i, err := strconv.ParseInt(matches[1], 10, 0)
if err == nil && i >= 1 && i <= 32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned something about Ethereum today. Didn't know they had fixed byte sizes 1-32. 👨‍🎓


func (f *Fabric) GetFFIParamValidator(ctx context.Context) (fftypes.FFIParamValidator, error) {
// Fabconnect does not require any additional validation beyond "JSON Schema correctness" at this time
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

ValidateContractLocation(ctx context.Context, location *fftypes.JSONAny) error

ValidateFFIParam(ctx context.Context, method *fftypes.FFIParam) error
// ValidateFFIParam(ctx context.Context, method *fftypes.FFIParam) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Contributor

@awrichar awrichar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really really good. Nice work wrangling this into a (nearly) standard schema.

@nguyer nguyer merged commit 32bad71 into hyperledger:main Jan 24, 2022
@nguyer nguyer deleted the json-schema branch January 24, 2022 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants