Skip to content

Conversation

@nguyer
Copy link
Contributor

@nguyer nguyer commented Feb 11, 2022

This PR adds an endpoint to automatically generate an FFI. The implementation is handled by the blockchain plugin. Right now, only the Ethereum plugin implements this functionality, but other blockchain plugins in the future could as well, if they have their own DSL to describe a smart contract.

Resolves #397

Signed-off-by: Nicko Guyer <nicko.guyer@kaleido.io>
Signed-off-by: Nicko Guyer <nicko.guyer@kaleido.io>
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
},
QueryParams: []*oapispec.QueryParam{
{Name: "confirm", Description: i18n.MsgConfirmQueryParam, IsBool: true, Example: "true"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this is unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Good catch, thanks.

GetContractSubscriptionByNameOrID(ctx context.Context, ns, nameOrID string) (*fftypes.ContractSubscription, error)
GetContractSubscriptions(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.ContractSubscription, *database.FilterResult, error)
DeleteContractSubscriptionByNameOrID(ctx context.Context, ns, nameOrID string) error
GenerateFFI(ctx context.Context, ns, name, version string, input *fftypes.JSONAny) (*fftypes.FFI, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we pass name and version here? Seems like the only usage of this method always sets them to empty strings.

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... maybe worth a quick chat about this one... I wrote the backend first and thought that it would make sense to pass in the name, version, etc. so it could be filled in on the generated FFI. Then I created the API endpoint and couldn't think of a good place to specify them when calling the API, because the payload of that request right now is entirely an ABI array.

One option would be to modify the endpoint to wrap the ABI elements in another object so that request would look like:

{
  "name": "...",
  "version": "...",
  "abi": [...]
}

return ctx.GetStub().PutState(name, assetJSON)
}

func (s *SmartContract) GetAsset(ctx contractapi.TransactionContextInterface, name string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No objections to this being added to the chaincode... but was it intended to be used in a test or something? Seems unused at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah this is being used in my other branch for additional tests :) It shouldn't have been in this commit. I'll remove it now for clarity.

Signed-off-by: Nicko Guyer <nicko.guyer@kaleido.io>
@codecov-commenter
Copy link

codecov-commenter commented Feb 15, 2022

Codecov Report

Merging #511 (b1bfff3) into main (b7e8078) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #511    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          275       276     +1     
  Lines        15731     15922   +191     
==========================================
+ Hits         15731     15922   +191     
Impacted Files Coverage Δ
pkg/fftypes/ffi.go 100.00% <ø> (ø)
...piserver/route_post_contract_interface_generate.go 100.00% <100.00%> (ø)
internal/blockchain/ethereum/ethereum.go 100.00% <100.00%> (ø)
internal/blockchain/fabric/fabric.go 100.00% <100.00%> (ø)
internal/contracts/manager.go 100.00% <100.00%> (ø)
pkg/wsclient/wsclient.go 100.00% <0.00%> (ø)
internal/metrics/metrics.go 100.00% <0.00%> (ø)
internal/dataexchange/ffdx/ffdx.go 100.00% <0.00%> (ø)
internal/events/operation_update.go 100.00% <0.00%> (ø)
internal/dataexchange/ffdx/config.go 100.00% <0.00%> (ø)
... and 5 more

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 b7e8078...b1bfff3. Read the comment docs.


func (cm *contractManager) GenerateFFI(ctx context.Context, ns string, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) {
if generationRequest.Namespace == "" {
generationRequest.Namespace = ns
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in general we ignore any nested Namespace value in an input body (ie list it in "ignored" fields so that Swagger won't generate it), and always write/overwrite with the one from the path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I didn't realize that. I did the exact opposite here. I'll switch it around to match the existing pattern. Thanks!

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 good; I think the new input body format is a lot better (and more future-proof). One minor comment left above.

Signed-off-by: Nicko Guyer <nicko.guyer@kaleido.io>
@nguyer nguyer merged commit fe435c1 into hyperledger:main Feb 17, 2022
@nguyer nguyer deleted the abi2ffi branch February 17, 2022 01:18
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.

Ethereum ABI to FFI conversion

3 participants