From e985589f221d336d1df2c417592106b9de44875c Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Fri, 17 Jun 2022 09:17:00 -0400 Subject: [PATCH 1/3] Move FFI/ABI conversion code to signer and common Signed-off-by: Nicko Guyer --- go.mod | 4 +- go.sum | 20 +- internal/apiserver/ffi2swagger.go | 16 +- internal/apiserver/ffi2swagger_test.go | 18 +- .../route_get_contract_api_interface.go | 4 +- .../route_get_contract_api_interface_test.go | 3 +- .../apiserver/route_get_contract_interface.go | 3 +- ...ute_get_contract_interface_name_version.go | 4 +- ...et_contract_interface_name_version_test.go | 5 +- .../route_get_contract_interface_test.go | 4 +- .../route_get_contract_interfaces.go | 4 +- .../route_get_contract_interfaces_test.go | 3 +- .../route_post_contract_interface_generate.go | 8 +- ...e_post_contract_interface_generate_test.go | 3 +- .../route_post_new_contract_interface.go | 8 +- .../route_post_new_contract_interface_test.go | 9 +- internal/apiserver/server_test.go | 6 +- internal/assets/token_pool.go | 12 +- internal/blockchain/ethereum/ethereum.go | 361 +------- internal/blockchain/ethereum/ethereum_test.go | 802 +----------------- .../ethereum/ffi_param_validator.go | 251 ------ .../ethereum/ffi_param_validator_test.go | 358 -------- internal/blockchain/fabric/fabric.go | 10 +- internal/blockchain/fabric/fabric_test.go | 18 +- internal/contracts/manager.go | 64 +- internal/contracts/manager_test.go | 326 +++---- internal/contracts/operations_test.go | 4 +- internal/coremsgs/en_api_translations.go | 1 - internal/data/blobstore.go | 2 +- internal/data/data_manager.go | 2 +- .../database/sqlcommon/contractapis_sql.go | 2 +- .../sqlcommon/contractapis_sql_test.go | 6 +- .../sqlcommon/contractlisteners_sql.go | 2 +- .../sqlcommon/contractlisteners_sql_test.go | 4 +- internal/database/sqlcommon/ffi_events_sql.go | 14 +- .../database/sqlcommon/ffi_events_sql_test.go | 16 +- .../database/sqlcommon/ffi_methods_sql.go | 12 +- .../sqlcommon/ffi_methods_sql_test.go | 16 +- internal/database/sqlcommon/ffi_sql.go | 16 +- internal/database/sqlcommon/ffi_sql_test.go | 16 +- .../definition_handler_contracts.go | 4 +- .../definition_handler_contracts_test.go | 18 +- internal/events/batch_pin_complete.go | 3 +- internal/namespace/manager.go | 7 +- internal/networkmap/data_query.go | 4 +- internal/orchestrator/data_query.go | 6 +- internal/orchestrator/subscriptions.go | 2 +- internal/reference/reference.go | 26 +- internal/txcommon/event_enrich_test.go | 2 +- mocks/apiservermocks/ffi_swagger_gen.go | 6 +- mocks/blockchainmocks/plugin.go | 32 +- mocks/contractmocks/manager.go | 72 +- mocks/databasemocks/plugin.go | 76 +- pkg/blockchain/plugin.go | 10 +- pkg/core/contract_listener.go | 4 +- pkg/core/contract_listener_test.go | 6 +- pkg/core/contracts.go | 22 +- pkg/core/datatype.go | 8 +- pkg/core/event.go | 2 +- pkg/core/ffi.go | 150 ---- pkg/core/ffi_param_validator.go | 96 --- pkg/core/ffi_param_validator_test.go | 35 - pkg/core/ffi_test.go | 150 ---- pkg/core/group.go | 6 +- pkg/core/identity.go | 6 +- pkg/core/message.go | 2 +- pkg/core/namespace.go | 17 +- pkg/core/operation.go | 2 +- pkg/core/stringarray.go | 5 +- pkg/core/tokenpool.go | 6 +- pkg/core/validations.go | 59 -- pkg/core/validations_test.go | 56 -- pkg/database/plugin.go | 22 +- test/e2e/ethereum_contract_test.go | 36 +- test/e2e/fabric_contract_test.go | 20 +- test/e2e/restclient_test.go | 8 +- 76 files changed, 593 insertions(+), 2830 deletions(-) delete mode 100644 internal/blockchain/ethereum/ffi_param_validator.go delete mode 100644 internal/blockchain/ethereum/ffi_param_validator_test.go delete mode 100644 pkg/core/ffi.go delete mode 100644 pkg/core/ffi_param_validator.go delete mode 100644 pkg/core/ffi_param_validator_test.go delete mode 100644 pkg/core/ffi_test.go delete mode 100644 pkg/core/validations.go delete mode 100644 pkg/core/validations_test.go diff --git a/go.mod b/go.mod index 46d127585c..f09c04d97a 100644 --- a/go.mod +++ b/go.mod @@ -13,8 +13,8 @@ require ( github.com/golang-migrate/migrate/v4 v4.15.2 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 - github.com/hyperledger/firefly-common v0.1.10 - github.com/hyperledger/firefly-signer v0.9.10 + github.com/hyperledger/firefly-common v0.1.11-0.20220616154518-160b5cf404cc + github.com/hyperledger/firefly-signer v0.9.11-0.20220617121121-907f2dd3b6fd github.com/jarcoal/httpmock v1.1.0 github.com/karlseguin/ccache v2.0.3+incompatible github.com/lib/pq v1.10.6 diff --git a/go.sum b/go.sum index 758f8d0bc5..70d9bf4f04 100644 --- a/go.sum +++ b/go.sum @@ -448,7 +448,6 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3 github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsouza/fake-gcs-server v1.17.0/go.mod h1:D1rTE4YCyHFNa99oyJJ5HyclvN/0uQR+pM/VdlL83bw= @@ -727,11 +726,10 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hyperledger/firefly-common v0.1.5/go.mod h1:qGy7i8eWlE8Ed7jFn2Hpn8bYaflL204j4NJB1mAfTms= -github.com/hyperledger/firefly-common v0.1.10 h1:BtP20uuPMP9+Q1+bRPJyBDCp5hObqd+JVMqoAoWBvVw= -github.com/hyperledger/firefly-common v0.1.10/go.mod h1:MYL6Dbj3KqM/79IkS+mCzJ7wRguNbd/PKdVu8aXo5TI= -github.com/hyperledger/firefly-signer v0.9.10 h1:pJgeuAH+q2qLuSSJ4sW3eZ9rd7oEyssCKDBNMj905As= -github.com/hyperledger/firefly-signer v0.9.10/go.mod h1:BjzIWMj4e1Em52liuyCV6dQhPeVc3WOuLOnEDGS4QK4= +github.com/hyperledger/firefly-common v0.1.11-0.20220616154518-160b5cf404cc h1:QLDIYiK9+CTIQ5a2F6zLbjIsxW1+VW4BGNBIkwTYQ9Q= +github.com/hyperledger/firefly-common v0.1.11-0.20220616154518-160b5cf404cc/go.mod h1:2NqPi5Ud9H6rSlZXkLbotxW7z4EAD89p3/8oNOpm9Gs= +github.com/hyperledger/firefly-signer v0.9.11-0.20220617121121-907f2dd3b6fd h1:dZiUGENFiU3i88C+smXY9ANUopBvjFaaCGRQbj55uKU= +github.com/hyperledger/firefly-signer v0.9.11-0.20220617121121-907f2dd3b6fd/go.mod h1:ycTpoDzq4/NS3F0Kq4u1ISdSW62xx6pMPMd3SkmB1UQ= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -1049,10 +1047,8 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9 github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.0.0-beta.8/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= @@ -1140,7 +1136,6 @@ github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfF github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= -github.com/sagikazarmark/crypt v0.5.0/go.mod h1:l+nzl7KWh51rpzp2h7t4MZWyiEWdhNpOAnclKvg+mdA= github.com/sagikazarmark/crypt v0.6.0/go.mod h1:U8+INwJo3nBv1m6A/8OBXAq7Jnpspk5AxSgDyEQcea8= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 h1:TToq11gyfNlrMFZiYujSekIsPd9AmsA2Bj/iv+s4JHE= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= @@ -1178,7 +1173,6 @@ github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo= github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= @@ -1198,7 +1192,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= -github.com/spf13/viper v1.11.0/go.mod h1:djo0X/bA5+tYVoCn+C7cAYJGcVn/qYLFTG8gdUsX7Zk= github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ= github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI= github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8= @@ -1280,13 +1273,10 @@ go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3CSBatqGNg7GRmsnfLWtoW60w4eDYfh7vHDg= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= -go.etcd.io/etcd/api/v3 v3.5.2/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/pkg/v3 v3.5.2/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= -go.etcd.io/etcd/client/v2 v2.305.2/go.mod h1:2D7ZejHVMIfog1221iLSYlQRzrtECw3kz4I4VAQm3qI= go.etcd.io/etcd/client/v2 v2.305.4/go.mod h1:Ud+VUwIi9/uQHOMA+4ekToJ12lTxlv0zB/+DHwTGEbU= go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= @@ -1369,7 +1359,6 @@ golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1674,7 +1663,6 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/apiserver/ffi2swagger.go b/internal/apiserver/ffi2swagger.go index e69209bc0f..d72353de62 100644 --- a/internal/apiserver/ffi2swagger.go +++ b/internal/apiserver/ffi2swagger.go @@ -36,7 +36,7 @@ import ( ) type FFISwaggerGen interface { - Generate(ctx context.Context, baseURL string, api *core.ContractAPI, ffi *core.FFI) *openapi3.T + Generate(ctx context.Context, baseURL string, api *core.ContractAPI, ffi *fftypes.FFI) *openapi3.T } type ContractListenerInput struct { @@ -58,7 +58,7 @@ func NewFFISwaggerGen() FFISwaggerGen { return &ffiSwaggerGen{} } -func (og *ffiSwaggerGen) Generate(ctx context.Context, baseURL string, api *core.ContractAPI, ffi *core.FFI) (swagger *openapi3.T) { +func (og *ffiSwaggerGen) Generate(ctx context.Context, baseURL string, api *core.ContractAPI, ffi *fftypes.FFI) (swagger *openapi3.T) { hasLocation := !api.Location.IsNil() routes := []*ffapi.Route{ @@ -67,7 +67,7 @@ func (og *ffiSwaggerGen) Generate(ctx context.Context, baseURL string, api *core Path: "interface", // must match a route defined in apiserver routes! Method: http.MethodGet, JSONInputValue: nil, - JSONOutputValue: func() interface{} { return &core.FFI{} }, + JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, }, } @@ -87,7 +87,7 @@ func (og *ffiSwaggerGen) Generate(ctx context.Context, baseURL string, api *core }).Generate(ctx, routes) } -func (og *ffiSwaggerGen) addMethod(routes []*ffapi.Route, method *core.FFIMethod, hasLocation bool) []*ffapi.Route { +func (og *ffiSwaggerGen) addMethod(routes []*ffapi.Route, method *fftypes.FFIMethod, hasLocation bool) []*ffapi.Route { ctx := context.Background() description := method.Description if method.Details != nil && len(method.Details) > 0 { @@ -115,7 +115,7 @@ func (og *ffiSwaggerGen) addMethod(routes []*ffapi.Route, method *core.FFIMethod return routes } -func (og *ffiSwaggerGen) addEvent(routes []*ffapi.Route, event *core.FFIEvent, hasLocation bool) []*ffapi.Route { +func (og *ffiSwaggerGen) addEvent(routes []*ffapi.Route, event *fftypes.FFIEvent, hasLocation bool) []*ffapi.Route { ctx := context.Background() description := event.Description if event.Details != nil && len(event.Details) > 0 { @@ -154,7 +154,7 @@ func (og *ffiSwaggerGen) addEvent(routes []*ffapi.Route, event *core.FFIEvent, h * Parse the FFI and build a corresponding JSON Schema to describe the request body for "invoke". * Returns the JSON Schema as an `fftypes.JSONObject`. */ -func contractCallJSONSchema(params *core.FFIParams, hasLocation bool) *fftypes.JSONObject { +func contractCallJSONSchema(params *fftypes.FFIParams, hasLocation bool) *fftypes.JSONObject { properties := fftypes.JSONObject{ "input": ffiParamsJSONSchema(params), "options": fftypes.JSONObject{ @@ -170,7 +170,7 @@ func contractCallJSONSchema(params *core.FFIParams, hasLocation bool) *fftypes.J } } -func ffiParamsJSONSchema(params *core.FFIParams) *fftypes.JSONObject { +func ffiParamsJSONSchema(params *fftypes.FFIParams) *fftypes.JSONObject { out := make(fftypes.JSONObject, len(*params)) for _, param := range *params { out[param.Name] = ffiParamJSONSchema(param) @@ -181,7 +181,7 @@ func ffiParamsJSONSchema(params *core.FFIParams) *fftypes.JSONObject { } } -func ffiParamJSONSchema(param *core.FFIParam) *fftypes.JSONObject { +func ffiParamJSONSchema(param *fftypes.FFIParam) *fftypes.JSONObject { out := fftypes.JSONObject{} if err := json.Unmarshal(param.Schema.Bytes(), &out); err == nil { return &out diff --git a/internal/apiserver/ffi2swagger_test.go b/internal/apiserver/ffi2swagger_test.go index e6a862b12f..1269c2c0dd 100644 --- a/internal/apiserver/ffi2swagger_test.go +++ b/internal/apiserver/ffi2swagger_test.go @@ -28,17 +28,17 @@ import ( "github.com/stretchr/testify/assert" ) -func testFFI() *core.FFI { - return &core.FFI{ +func testFFI() *fftypes.FFI { + return &fftypes.FFI{ ID: fftypes.NewUUID(), Namespace: "ns1", Name: "math", Version: "v1.0.0", - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "method1", Pathname: "method1", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -59,7 +59,7 @@ func testFFI() *core.FFI { }`), }, }, - Returns: core.FFIParams{ + Returns: fftypes.FFIParams{ { Name: "success", Schema: fftypes.JSONAnyPtr(`{"type": "boolean"}`), @@ -76,13 +76,13 @@ func testFFI() *core.FFI { /* no params */ }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { ID: fftypes.NewUUID(), Pathname: "event1", - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "event1", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "result", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -186,7 +186,7 @@ func TestGenerateWithLocation(t *testing.T) { } func TestFFIParamBadSchema(t *testing.T) { - param := &core.FFIParam{ + param := &fftypes.FFIParam{ Name: "test", Schema: fftypes.JSONAnyPtr(`{`), } diff --git a/internal/apiserver/route_get_contract_api_interface.go b/internal/apiserver/route_get_contract_api_interface.go index 4e997bc46c..20c66c8142 100644 --- a/internal/apiserver/route_get_contract_api_interface.go +++ b/internal/apiserver/route_get_contract_api_interface.go @@ -20,8 +20,8 @@ import ( "net/http" "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" ) var getContractAPIInterface = &ffapi.Route{ @@ -34,7 +34,7 @@ var getContractAPIInterface = &ffapi.Route{ QueryParams: nil, Description: coremsgs.APIEndpointsGetContractAPIInterface, JSONInputValue: nil, - JSONOutputValue: func() interface{} { return &core.FFI{} }, + JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_get_contract_api_interface_test.go b/internal/apiserver/route_get_contract_api_interface_test.go index 139122e236..099649bd19 100644 --- a/internal/apiserver/route_get_contract_api_interface_test.go +++ b/internal/apiserver/route_get_contract_api_interface_test.go @@ -22,6 +22,7 @@ import ( "net/http/httptest" "testing" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/mocks/contractmocks" "github.com/hyperledger/firefly/pkg/core" "github.com/stretchr/testify/assert" @@ -40,7 +41,7 @@ func TestGetContractAPIInterface(t *testing.T) { res := httptest.NewRecorder() mcm.On("GetContractAPIInterface", mock.Anything, "ns1", "banana"). - Return(&core.FFI{}, nil) + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/route_get_contract_interface.go b/internal/apiserver/route_get_contract_interface.go index 933b47da33..05365baa88 100644 --- a/internal/apiserver/route_get_contract_interface.go +++ b/internal/apiserver/route_get_contract_interface.go @@ -23,7 +23,6 @@ import ( "github.com/hyperledger/firefly-common/pkg/ffapi" "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" ) var getContractInterface = &ffapi.Route{ @@ -38,7 +37,7 @@ var getContractInterface = &ffapi.Route{ }, Description: coremsgs.APIEndpointsGetContractInterface, JSONInputValue: nil, - JSONOutputValue: func() interface{} { return &core.FFI{} }, + JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_get_contract_interface_name_version.go b/internal/apiserver/route_get_contract_interface_name_version.go index b428929f14..ef9c420fce 100644 --- a/internal/apiserver/route_get_contract_interface_name_version.go +++ b/internal/apiserver/route_get_contract_interface_name_version.go @@ -21,8 +21,8 @@ import ( "strings" "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" ) var getContractInterfaceNameVersion = &ffapi.Route{ @@ -38,7 +38,7 @@ var getContractInterfaceNameVersion = &ffapi.Route{ }, Description: coremsgs.APIEndpointsGetContractInterfaceNameVersion, JSONInputValue: nil, - JSONOutputValue: func() interface{} { return &core.FFI{} }, + JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { diff --git a/internal/apiserver/route_get_contract_interface_name_version_test.go b/internal/apiserver/route_get_contract_interface_name_version_test.go index 0cb2743552..0b3c18a5f7 100644 --- a/internal/apiserver/route_get_contract_interface_name_version_test.go +++ b/internal/apiserver/route_get_contract_interface_name_version_test.go @@ -22,6 +22,7 @@ import ( "net/http/httptest" "testing" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/mocks/contractmocks" "github.com/hyperledger/firefly/pkg/core" "github.com/stretchr/testify/assert" @@ -40,7 +41,7 @@ func TestGetContractInterfaceNameVersion(t *testing.T) { res := httptest.NewRecorder() mcm.On("GetFFI", mock.Anything, "ns1", "banana", "v1.0.0"). - Return(&core.FFI{}, nil) + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) @@ -58,7 +59,7 @@ func TestGetContractInterfaceNameVersionWithChildren(t *testing.T) { res := httptest.NewRecorder() mcm.On("GetFFIWithChildren", mock.Anything, "ns1", "banana", "v1.0.0"). - Return(&core.FFI{}, nil) + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/route_get_contract_interface_test.go b/internal/apiserver/route_get_contract_interface_test.go index c98dd829f0..b1bd18b5bd 100644 --- a/internal/apiserver/route_get_contract_interface_test.go +++ b/internal/apiserver/route_get_contract_interface_test.go @@ -56,7 +56,7 @@ func TestGetContractInterface(t *testing.T) { res := httptest.NewRecorder() mcm.On("GetFFIByID", mock.Anything, id). - Return(&core.FFI{}, nil) + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) @@ -75,7 +75,7 @@ func TestGetContractInterfaceWithChildren(t *testing.T) { res := httptest.NewRecorder() mcm.On("GetFFIByIDWithChildren", mock.Anything, id). - Return(&core.FFI{}, nil) + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/route_get_contract_interfaces.go b/internal/apiserver/route_get_contract_interfaces.go index e47434644d..6197d393c7 100644 --- a/internal/apiserver/route_get_contract_interfaces.go +++ b/internal/apiserver/route_get_contract_interfaces.go @@ -20,8 +20,8 @@ import ( "net/http" "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" "github.com/hyperledger/firefly/pkg/database" ) @@ -33,7 +33,7 @@ var getContractInterfaces = &ffapi.Route{ QueryParams: nil, Description: coremsgs.APIEndpointsGetContractInterfaces, JSONInputValue: nil, - JSONOutputValue: func() interface{} { return []*core.FFI{} }, + JSONOutputValue: func() interface{} { return []*fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ FilterFactory: database.FFIQueryFactory, diff --git a/internal/apiserver/route_get_contract_interfaces_test.go b/internal/apiserver/route_get_contract_interfaces_test.go index 2228605d78..5883d142e7 100644 --- a/internal/apiserver/route_get_contract_interfaces_test.go +++ b/internal/apiserver/route_get_contract_interfaces_test.go @@ -22,6 +22,7 @@ import ( "net/http/httptest" "testing" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/mocks/contractmocks" "github.com/hyperledger/firefly/pkg/core" "github.com/stretchr/testify/assert" @@ -40,7 +41,7 @@ func TestGetContractInterfaces(t *testing.T) { res := httptest.NewRecorder() mcm.On("GetFFIs", mock.Anything, "ns1", mock.Anything). - Return([]*core.FFI{}, nil, nil) + Return([]*fftypes.FFI{}, nil, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/route_post_contract_interface_generate.go b/internal/apiserver/route_post_contract_interface_generate.go index 3d3d1805a6..96163a96ec 100644 --- a/internal/apiserver/route_post_contract_interface_generate.go +++ b/internal/apiserver/route_post_contract_interface_generate.go @@ -20,8 +20,8 @@ import ( "net/http" "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" ) var postContractInterfaceGenerate = &ffapi.Route{ @@ -31,12 +31,12 @@ var postContractInterfaceGenerate = &ffapi.Route{ PathParams: nil, QueryParams: []*ffapi.QueryParam{}, Description: coremsgs.APIEndpointsPostContractInterfaceGenerate, - JSONInputValue: func() interface{} { return &core.FFIGenerationRequest{} }, - JSONOutputValue: func() interface{} { return &core.FFI{} }, + JSONInputValue: func() interface{} { return &fftypes.FFIGenerationRequest{} }, + JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { - generationRequest := r.Input.(*core.FFIGenerationRequest) + generationRequest := r.Input.(*fftypes.FFIGenerationRequest) return cr.or.Contracts().GenerateFFI(cr.ctx, extractNamespace(r.PP), generationRequest) }, }, diff --git a/internal/apiserver/route_post_contract_interface_generate_test.go b/internal/apiserver/route_post_contract_interface_generate_test.go index 64073cb603..90e42ad716 100644 --- a/internal/apiserver/route_post_contract_interface_generate_test.go +++ b/internal/apiserver/route_post_contract_interface_generate_test.go @@ -22,6 +22,7 @@ import ( "net/http/httptest" "testing" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/mocks/contractmocks" "github.com/hyperledger/firefly/pkg/core" "github.com/stretchr/testify/assert" @@ -40,7 +41,7 @@ func TestPostContractInterfaceGenerate(t *testing.T) { res := httptest.NewRecorder() mcm.On("GenerateFFI", mock.Anything, "ns1", mock.Anything). - Return(&core.FFI{}, nil) + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/route_post_new_contract_interface.go b/internal/apiserver/route_post_new_contract_interface.go index b16643201b..abf536d779 100644 --- a/internal/apiserver/route_post_new_contract_interface.go +++ b/internal/apiserver/route_post_new_contract_interface.go @@ -21,8 +21,8 @@ import ( "strings" "github.com/hyperledger/firefly-common/pkg/ffapi" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/internal/coremsgs" - "github.com/hyperledger/firefly/pkg/core" ) var postNewContractInterface = &ffapi.Route{ @@ -34,14 +34,14 @@ var postNewContractInterface = &ffapi.Route{ {Name: "confirm", Description: coremsgs.APIConfirmQueryParam, IsBool: true, Example: "true"}, }, Description: coremsgs.APIEndpointsPostNewContractInterface, - JSONInputValue: func() interface{} { return &core.FFI{} }, - JSONOutputValue: func() interface{} { return &core.FFI{} }, + JSONInputValue: func() interface{} { return &fftypes.FFI{} }, + JSONOutputValue: func() interface{} { return &fftypes.FFI{} }, JSONOutputCodes: []int{http.StatusOK}, Extensions: &coreExtensions{ CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) { waitConfirm := strings.EqualFold(r.QP["confirm"], "true") r.SuccessStatus = syncRetcode(waitConfirm) - return cr.or.Contracts().BroadcastFFI(cr.ctx, extractNamespace(r.PP), r.Input.(*core.FFI), waitConfirm) + return cr.or.Contracts().BroadcastFFI(cr.ctx, extractNamespace(r.PP), r.Input.(*fftypes.FFI), waitConfirm) }, }, } diff --git a/internal/apiserver/route_post_new_contract_interface_test.go b/internal/apiserver/route_post_new_contract_interface_test.go index b982e3b76d..13063d9b3b 100644 --- a/internal/apiserver/route_post_new_contract_interface_test.go +++ b/internal/apiserver/route_post_new_contract_interface_test.go @@ -22,6 +22,7 @@ import ( "net/http/httptest" "testing" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly/mocks/contractmocks" "github.com/hyperledger/firefly/pkg/core" "github.com/stretchr/testify/assert" @@ -39,8 +40,8 @@ func TestPostNewContractInterface(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("BroadcastFFI", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), false). - Return(&core.FFI{}, nil) + mcm.On("BroadcastFFI", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.FFI"), false). + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 202, res.Result().StatusCode) @@ -57,8 +58,8 @@ func TestPostNewContractInterfaceSync(t *testing.T) { req.Header.Set("Content-Type", "application/json; charset=utf-8") res := httptest.NewRecorder() - mcm.On("BroadcastFFI", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), true). - Return(&core.FFI{}, nil) + mcm.On("BroadcastFFI", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.FFI"), true). + Return(&fftypes.FFI{}, nil) r.ServeHTTP(res, req) assert.Equal(t, 200, res.Result().StatusCode) diff --git a/internal/apiserver/server_test.go b/internal/apiserver/server_test.go index 3821e660dd..5fd334d721 100644 --- a/internal/apiserver/server_test.go +++ b/internal/apiserver/server_test.go @@ -254,9 +254,9 @@ func TestContractAPISwaggerJSON(t *testing.T) { s := httptest.NewServer(r) defer s.Close() - ffi := &core.FFI{} + ffi := &fftypes.FFI{} api := &core.ContractAPI{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -309,7 +309,7 @@ func TestContractAPISwaggerJSONGetFFIFail(t *testing.T) { defer s.Close() api := &core.ContractAPI{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } diff --git a/internal/assets/token_pool.go b/internal/assets/token_pool.go index 2134d4f82a..d463c2ee37 100644 --- a/internal/assets/token_pool.go +++ b/internal/assets/token_pool.go @@ -32,7 +32,7 @@ func (am *assetManager) CreateTokenPool(ctx context.Context, ns string, pool *co if err := am.data.VerifyNamespaceExists(ctx, ns); err != nil { return nil, err } - if err := core.ValidateFFNameFieldNoUUID(ctx, pool.Name, "name"); err != nil { + if err := fftypes.ValidateFFNameFieldNoUUID(ctx, pool.Name, "name"); err != nil { return nil, err } if existing, err := am.database.GetTokenPool(ctx, ns, pool.Name); err != nil { @@ -137,7 +137,7 @@ func (am *assetManager) ActivateTokenPool(ctx context.Context, pool *core.TokenP } func (am *assetManager) GetTokenPools(ctx context.Context, ns string, filter database.AndFilter) ([]*core.TokenPool, *database.FilterResult, error) { - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return nil, nil, err } return am.database.GetTokenPools(ctx, am.scopeNS(ns, filter)) @@ -147,10 +147,10 @@ func (am *assetManager) GetTokenPool(ctx context.Context, ns, connector, poolNam if _, err := am.selectTokenPlugin(ctx, connector); err != nil { return nil, err } - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return nil, err } - if err := core.ValidateFFNameFieldNoUUID(ctx, poolName, "name"); err != nil { + if err := fftypes.ValidateFFNameFieldNoUUID(ctx, poolName, "name"); err != nil { return nil, err } pool, err := am.database.GetTokenPool(ctx, ns, poolName) @@ -164,7 +164,7 @@ func (am *assetManager) GetTokenPool(ctx context.Context, ns, connector, poolNam } func (am *assetManager) GetTokenPoolByNameOrID(ctx context.Context, ns, poolNameOrID string) (*core.TokenPool, error) { - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return nil, err } @@ -172,7 +172,7 @@ func (am *assetManager) GetTokenPoolByNameOrID(ctx context.Context, ns, poolName poolID, err := fftypes.ParseUUID(ctx, poolNameOrID) if err != nil { - if err := core.ValidateFFNameField(ctx, poolNameOrID, "name"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, poolNameOrID, "name"); err != nil { return nil, err } if pool, err = am.database.GetTokenPool(ctx, ns, poolNameOrID); err != nil { diff --git a/internal/blockchain/ethereum/ethereum.go b/internal/blockchain/ethereum/ethereum.go index 74389618a7..791f0529dd 100644 --- a/internal/blockchain/ethereum/ethereum.go +++ b/internal/blockchain/ethereum/ethereum.go @@ -34,23 +34,15 @@ import ( "github.com/hyperledger/firefly-common/pkg/log" "github.com/hyperledger/firefly-common/pkg/wsclient" "github.com/hyperledger/firefly-signer/pkg/abi" + "github.com/hyperledger/firefly-signer/pkg/ffi" "github.com/hyperledger/firefly/internal/coremsgs" "github.com/hyperledger/firefly/internal/metrics" "github.com/hyperledger/firefly/pkg/blockchain" "github.com/hyperledger/firefly/pkg/core" - "github.com/santhosh-tekuri/jsonschema/v5" ) const ( broadcastBatchEventSignature = "BatchPin(address,uint256,string,bytes32,bytes32,string,bytes32[])" - addressType = "address" - boolType = "bool" - booleanType = "boolean" - integerType = "integer" - tupleType = "tuple" - stringType = "string" - arrayType = "array" - objectType = "object" ) type Ethereum struct { @@ -138,31 +130,6 @@ type Location struct { Address string `json:"address"` } -type paramDetails struct { - Type string `json:"type"` - InternalType string `json:"internalType,omitempty"` - Indexed bool `json:"indexed,omitempty"` - Index *int `json:"index,omitempty"` -} - -type Schema struct { - OneOf []SchemaType `json:"oneOf,omitempty"` - Type string `json:"type,omitempty"` - Details *paramDetails `json:"details,omitempty"` - Properties map[string]*Schema `json:"properties,omitempty"` - Items *Schema `json:"items,omitempty"` - Description string `json:"description,omitempty"` -} - -type SchemaType struct { - Type string `json:"type"` -} - -func (s *Schema) ToJSON() string { - b, _ := json.Marshal(s) - return string(b) -} - type EthconnectMessageRequest struct { Headers EthconnectMessageHeaders `json:"headers,omitempty"` To string `json:"to"` @@ -748,7 +715,7 @@ func (e *Ethereum) SubmitNetworkAction(ctx context.Context, nsOpID string, signi return e.invokeContractMethod(ctx, address, signingKey, batchPinMethodABI, nsOpID, input, nil) } -func (e *Ethereum) InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) error { +func (e *Ethereum) InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) error { ethereumLocation, err := parseContractLocation(ctx, location) if err != nil { return err @@ -760,7 +727,7 @@ func (e *Ethereum) InvokeContract(ctx context.Context, nsOpID string, signingKey return e.invokeContractMethod(ctx, ethereumLocation.Address, signingKey, abi, nsOpID, orderedInput, options) } -func (e *Ethereum) QueryContract(ctx context.Context, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) { +func (e *Ethereum) QueryContract(ctx context.Context, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) { ethereumLocation, err := parseContractLocation(ctx, location) if err != nil { return nil, err @@ -812,13 +779,17 @@ func (e *Ethereum) AddContractListener(ctx context.Context, listener *core.Contr if err != nil { return err } - abi, err := e.FFIEventDefinitionToABI(ctx, &listener.Event.FFIEventDefinition) + abi, err := ffi.ConvertFFIEventDefinitionToABI(ctx, &listener.Event.FFIEventDefinition) if err != nil { return i18n.WrapError(ctx, err, coremsgs.MsgContractParamInvalid) } subName := fmt.Sprintf("ff-sub-%s", listener.ID) - result, err := e.streams.createSubscription(ctx, location, e.streamID, subName, listener.Options.FirstEvent, abi) + firstEvent := string(core.SubOptsFirstEventNewest) + if listener.Options != nil { + firstEvent = listener.Options.FirstEvent + } + result, err := e.streams.createSubscription(ctx, location, e.streamID, subName, firstEvent, abi) if err != nil { return err } @@ -830,157 +801,21 @@ func (e *Ethereum) DeleteContractListener(ctx context.Context, subscription *cor return e.streams.deleteSubscription(ctx, subscription.BackendID) } -func (e *Ethereum) GetFFIParamValidator(ctx context.Context) (core.FFIParamValidator, error) { - return &FFIParamValidator{}, nil -} - -func (e *Ethereum) FFIEventDefinitionToABI(ctx context.Context, event *core.FFIEventDefinition) (*abi.Entry, error) { - abiInputs, err := e.convertFFIParamsToABIParameters(ctx, event.Params) - if err != nil { - return nil, err - } - abiEntry := &abi.Entry{ - Name: event.Name, - Type: "event", - Inputs: abiInputs, - } - if event.Details != nil { - abiEntry.Anonymous = event.Details.GetBool("anonymous") - } - return abiEntry, nil +func (e *Ethereum) GetFFIParamValidator(ctx context.Context) (fftypes.FFIParamValidator, error) { + return &ffi.ParamValidator{}, nil } -func (e *Ethereum) FFIMethodToABI(ctx context.Context, method *core.FFIMethod, input map[string]interface{}) (*abi.Entry, error) { - abiInputs, err := e.convertFFIParamsToABIParameters(ctx, method.Params) - if err != nil { - return nil, err - } - - abiOutputs, err := e.convertFFIParamsToABIParameters(ctx, method.Returns) - if err != nil { - return nil, err - } - abiEntry := &abi.Entry{ - Name: method.Name, - Type: "function", - Inputs: abiInputs, - Outputs: abiOutputs, - } - if method.Details != nil { - if stateMutability, ok := method.Details.GetStringOk("stateMutability"); ok { - abiEntry.StateMutability = abi.StateMutability(stateMutability) - } - abiEntry.Payable = method.Details.GetBool("payable") - abiEntry.Constant = method.Details.GetBool("constant") - } - return abiEntry, nil -} - -func ABIArgumentToTypeString(typeName string, components abi.ParameterArray) string { - if strings.HasPrefix(typeName, "tuple") { - suffix := typeName[5:] - children := make([]string, len(components)) - for i, component := range components { - children[i] = ABIArgumentToTypeString(component.Type, nil) - } - return "(" + strings.Join(children, ",") + ")" + suffix - } - return typeName -} - -func ABIMethodToSignature(abi *abi.Entry) string { - result := abi.Name + "(" - if len(abi.Inputs) > 0 { - types := make([]string, len(abi.Inputs)) - for i, param := range abi.Inputs { - types[i] = ABIArgumentToTypeString(param.Type, param.Components) - } - result += strings.Join(types, ",") - } - result += ")" - return result -} - -func (e *Ethereum) GenerateEventSignature(ctx context.Context, event *core.FFIEventDefinition) string { - abi, err := e.FFIEventDefinitionToABI(ctx, event) +func (e *Ethereum) GenerateEventSignature(ctx context.Context, event *fftypes.FFIEventDefinition) string { + abi, err := ffi.ConvertFFIEventDefinitionToABI(ctx, event) if err != nil { return "" } - return ABIMethodToSignature(abi) -} - -func (e *Ethereum) convertFFIParamsToABIParameters(ctx context.Context, params core.FFIParams) (abi.ParameterArray, error) { - abiParamList := make(abi.ParameterArray, len(params)) - for i, param := range params { - c := core.NewFFISchemaCompiler() - v, _ := e.GetFFIParamValidator(ctx) - c.RegisterExtension(v.GetExtensionName(), v.GetMetaSchema(), v) - err := c.AddResource(param.Name, strings.NewReader(param.Schema.String())) - if err != nil { - return nil, err - } - s, err := c.Compile(param.Name) - if err != nil { - return nil, err - } - abiParamList[i] = processField(param.Name, s) - } - return abiParamList, nil -} - -func processField(name string, schema *jsonschema.Schema) *abi.Parameter { - details := getParamDetails(schema) - parameter := &abi.Parameter{ - Name: name, - Type: details.Type, - InternalType: details.InternalType, - Indexed: details.Indexed, - } - if len(schema.Types) > 0 { - switch schema.Types[0] { - case objectType: - parameter.Components = buildABIParameterArrayForObject(schema.Properties) - case arrayType: - parameter.Components = buildABIParameterArrayForObject(schema.Items2020.Properties) - } - } - return parameter + return ffi.ABIMethodToSignature(abi) } -func buildABIParameterArrayForObject(properties map[string]*jsonschema.Schema) abi.ParameterArray { - parameters := make(abi.ParameterArray, len(properties)) - for propertyName, propertySchema := range properties { - details := getParamDetails(propertySchema) - parameter := processField(propertyName, propertySchema) - parameters[*details.Index] = parameter - } - return parameters -} - -func getParamDetails(schema *jsonschema.Schema) *paramDetails { - ext := schema.Extensions["details"] - details := ext.(detailsSchema) - blockchainType := details["type"].(string) - paramDetails := ¶mDetails{ - Type: blockchainType, - } - if i, ok := details["index"]; ok { - index, _ := i.(json.Number).Int64() - paramDetails.Index = new(int) - *paramDetails.Index = int(index) - } - if i, ok := details["indexed"]; ok { - paramDetails.Indexed = i.(bool) - } - if i, ok := details["internalType"]; ok { - paramDetails.InternalType = i.(string) - } - return paramDetails -} - -func (e *Ethereum) prepareRequest(ctx context.Context, method *core.FFIMethod, input map[string]interface{}) (*abi.Entry, []interface{}, error) { +func (e *Ethereum) prepareRequest(ctx context.Context, method *fftypes.FFIMethod, input map[string]interface{}) (*abi.Entry, []interface{}, error) { orderedInput := make([]interface{}, len(method.Params)) - abi, err := e.FFIMethodToABI(ctx, method, input) + abi, err := ffi.ConvertFFIMethodToABI(ctx, method) if err != nil { return abi, orderedInput, err } @@ -1005,7 +840,7 @@ func (e *Ethereum) getContractAddress(ctx context.Context, instancePath string) return output["address"], nil } -func (e *Ethereum) GenerateFFI(ctx context.Context, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) { +func (e *Ethereum) GenerateFFI(ctx context.Context, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) { var input FFIGenerationInput err := json.Unmarshal(generationRequest.Input.Bytes(), &input) if err != nil { @@ -1014,167 +849,7 @@ func (e *Ethereum) GenerateFFI(ctx context.Context, generationRequest *core.FFIG if len(*input.ABI) == 0 { return nil, i18n.NewError(ctx, coremsgs.MsgFFIGenerationFailed, "ABI is empty") } - return e.convertABIToFFI(ctx, generationRequest.Namespace, generationRequest.Name, generationRequest.Version, generationRequest.Description, input.ABI) -} - -func (e *Ethereum) convertABIToFFI(ctx context.Context, ns, name, version, description string, abi *abi.ABI) (*core.FFI, error) { - ffi := &core.FFI{ - Namespace: ns, - Name: name, - Version: version, - Description: description, - Methods: make([]*core.FFIMethod, len(abi.Functions())), - Events: make([]*core.FFIEvent, len(abi.Events())), - } - i := 0 - for _, f := range abi.Functions() { - method, err := e.convertABIFunctionToFFIMethod(ctx, f) - if err != nil { - return nil, err - } - ffi.Methods[i] = method - i++ - } - i = 0 - for _, f := range abi.Events() { - event, err := e.convertABIEventToFFIEvent(ctx, f) - if err != nil { - return nil, err - } - ffi.Events[i] = event - i++ - } - return ffi, nil -} - -func (e *Ethereum) convertABIFunctionToFFIMethod(ctx context.Context, abiFunction *abi.Entry) (*core.FFIMethod, error) { - params := make([]*core.FFIParam, len(abiFunction.Inputs)) - returns := make([]*core.FFIParam, len(abiFunction.Outputs)) - details := map[string]interface{}{} - for i, input := range abiFunction.Inputs { - typeComponent, err := input.TypeComponentTreeCtx(ctx) - if err != nil { - return nil, err - } - schema := e.getSchemaForABIInput(ctx, typeComponent) - param := &core.FFIParam{ - Name: input.Name, - Schema: fftypes.JSONAnyPtr(schema.ToJSON()), - } - params[i] = param - } - for i, output := range abiFunction.Outputs { - typeComponent, err := output.TypeComponentTreeCtx(ctx) - if err != nil { - return nil, err - } - schema := e.getSchemaForABIInput(ctx, typeComponent) - param := &core.FFIParam{ - Name: output.Name, - Schema: fftypes.JSONAnyPtr(schema.ToJSON()), - } - returns[i] = param - } - if abiFunction.StateMutability != "" { - details["stateMutability"] = string(abiFunction.StateMutability) - } - if abiFunction.Payable { - details["payable"] = true - } - if abiFunction.Constant { - details["constant"] = true - } - return &core.FFIMethod{ - Name: abiFunction.Name, - Params: params, - Returns: returns, - Details: details, - }, nil -} - -func (e *Ethereum) convertABIEventToFFIEvent(ctx context.Context, abiEvent *abi.Entry) (*core.FFIEvent, error) { - params := make([]*core.FFIParam, len(abiEvent.Inputs)) - details := map[string]interface{}{} - for i, output := range abiEvent.Inputs { - typeComponent, err := output.TypeComponentTreeCtx(ctx) - if err != nil { - return nil, err - } - schema := e.getSchemaForABIInput(ctx, typeComponent) - param := &core.FFIParam{ - Name: output.Name, - Schema: fftypes.JSONAnyPtr(schema.ToJSON()), - } - params[i] = param - } - if abiEvent.Anonymous { - details["anonymous"] = true - } - return &core.FFIEvent{ - FFIEventDefinition: core.FFIEventDefinition{ - Name: abiEvent.Name, - Params: params, - Details: details, - }, - }, nil -} - -func (e *Ethereum) getSchemaForABIInput(ctx context.Context, typeComponent abi.TypeComponent) *Schema { - schema := &Schema{ - Details: ¶mDetails{ - Type: typeComponent.Parameter().Type, - InternalType: typeComponent.Parameter().InternalType, - Indexed: typeComponent.Parameter().Indexed, - }, - } - switch typeComponent.ComponentType() { - case abi.ElementaryComponent: - t := e.getFFIType(typeComponent.ElementaryType().String()) - if t == core.FFIInputTypeInteger { - schema.OneOf = []SchemaType{ - {Type: "string"}, - {Type: "integer"}, - } - schema.Description = i18n.Expand(ctx, coremsgs.APIIntegerDescription) - } else { - schema.Type = t.String() - } - case abi.FixedArrayComponent, abi.DynamicArrayComponent: - schema.Type = arrayType - childSchema := e.getSchemaForABIInput(ctx, typeComponent.ArrayChild()) - schema.Items = childSchema - schema.Details = childSchema.Details - childSchema.Details = nil - case abi.TupleComponent: - schema.Type = objectType - schema.Properties = make(map[string]*Schema, len(typeComponent.TupleChildren())) - for i, tupleChild := range typeComponent.TupleChildren() { - childSchema := e.getSchemaForABIInput(ctx, tupleChild) - childSchema.Details.Index = new(int) - *childSchema.Details.Index = i - schema.Properties[tupleChild.KeyName()] = childSchema - } - } - return schema -} - -func (e *Ethereum) getFFIType(solidityType string) core.FFIInputType { - switch solidityType { - case stringType, "address": - return core.FFIInputTypeString - case boolType: - return core.FFIInputTypeBoolean - case tupleType: - return core.FFIInputTypeObject - default: - switch { - case strings.Contains(solidityType, "byte"): - return core.FFIInputTypeString - case strings.Contains(solidityType, "int"): - return core.FFIInputTypeInteger - } - } - return "" + return ffi.ConvertABIToFFI(ctx, generationRequest.Namespace, generationRequest.Name, generationRequest.Version, generationRequest.Description, input.ABI) } func (e *Ethereum) getNetworkVersion(ctx context.Context, address string) (int, error) { diff --git a/internal/blockchain/ethereum/ethereum_test.go b/internal/blockchain/ethereum/ethereum_test.go index df6e2d754e..c3569b0997 100644 --- a/internal/blockchain/ethereum/ethereum_test.go +++ b/internal/blockchain/ethereum/ethereum_test.go @@ -28,12 +28,9 @@ import ( "github.com/hyperledger/firefly-common/pkg/config" "github.com/hyperledger/firefly-common/pkg/ffresty" "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/hyperledger/firefly-common/pkg/i18n" "github.com/hyperledger/firefly-common/pkg/log" "github.com/hyperledger/firefly-common/pkg/wsclient" - "github.com/hyperledger/firefly-signer/pkg/abi" "github.com/hyperledger/firefly/internal/coreconfig" - "github.com/hyperledger/firefly/internal/coremsgs" "github.com/hyperledger/firefly/mocks/blockchainmocks" "github.com/hyperledger/firefly/mocks/metricsmocks" "github.com/hyperledger/firefly/mocks/wsmocks" @@ -49,10 +46,10 @@ var utEthconnectConf = utConfig.SubSection(EthconnectConfigKey) var utAddressResolverConf = utConfig.SubSection(AddressResolverConfigKey) var utFFTMConf = utConfig.SubSection(FFTMConfigKey) -func testFFIMethod() *core.FFIMethod { - return &core.FFIMethod{ +func testFFIMethod() *fftypes.FFIMethod { + return &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"oneOf":[{"type":"string"},{"type":"integer"}],"details":{"type":"uint256"}}`), @@ -62,7 +59,7 @@ func testFFIMethod() *core.FFIMethod { Schema: fftypes.JSONAnyPtr(`{"oneOf":[{"type":"string"},{"type":"integer"}],"details":{"type":"uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"oneOf":[{"type":"string"},{"type":"integer"}],"details":{"type":"uint256"}}`), @@ -1617,10 +1614,10 @@ func TestFormatNil(t *testing.T) { assert.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", ethHexFormatB32(nil)) } -func encodeDetails(internalType string) *fftypes.JSONAny { - result, _ := json.Marshal(¶mDetails{Type: internalType}) - return fftypes.JSONAnyPtrBytes(result) -} +// func encodeDetails(internalType string) *fftypes.JSONAny { +// result, _ := json.Marshal(¶mDetails{Type: internalType}) +// return fftypes.JSONAnyPtrBytes(result) +// } func TestAddSubscription(t *testing.T) { e, cancel := newTestEthereum() @@ -1638,9 +1635,9 @@ func TestAddSubscription(t *testing.T) { "address": "0x123", }.String()), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "Changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "string", "details": {"type": "string"}}`), @@ -1678,9 +1675,9 @@ func TestAddSubscriptionBadParamDetails(t *testing.T) { "address": "0x123", }.String()), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "Changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "string", "details": {"type": ""}}`), @@ -2053,9 +2050,9 @@ func TestInvokeContractPrepareFail(t *testing.T) { location := &Location{ Address: "0x12345", } - method := &core.FFIMethod{ + method := &fftypes.FFIMethod{ Name: "set", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Schema: fftypes.JSONAnyPtr("{bad schema!"), }, @@ -2138,8 +2135,8 @@ func TestQueryContractErrorPrepare(t *testing.T) { location := &Location{ Address: "0x12345", } - method := &core.FFIMethod{ - Params: core.FFIParams{ + method := &fftypes.FFIMethod{ + Params: fftypes.FFIParams{ { Name: "bad", Schema: fftypes.JSONAnyPtr("{badschema}"), @@ -2282,636 +2279,9 @@ func TestGetContractAddressBadJSON(t *testing.T) { assert.Regexp(t, "invalid character 'n' looking for beginning of object key string", err) } -func TestFFIMethodToABI(t *testing.T) { - e, _ := newTestEthereum() - - method := &core.FFIMethod{ - Name: "set", - Params: []*core.FFIParam{ - { - Name: "newValue", - Schema: fftypes.JSONAnyPtr(`{ - "type": "integer", - "details": { - "type": "uint256" - } - }`), - }, - }, - Returns: []*core.FFIParam{}, - } - - expectedABIElement := &abi.Entry{ - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "newValue", - Type: "uint256", - Indexed: false, - }, - }, - Outputs: abi.ParameterArray{}, - } - - abi, err := e.FFIMethodToABI(context.Background(), method, nil) - assert.NoError(t, err) - assert.Equal(t, expectedABIElement, abi) -} - -func TestFFIMethodToABIObject(t *testing.T) { - e, _ := newTestEthereum() - - method := &core.FFIMethod{ - Name: "set", - Params: []*core.FFIParam{ - { - Name: "widget", - Schema: fftypes.JSONAnyPtr(`{ - "type": "object", - "details": { - "type": "tuple" - }, - "properties": { - "radius": { - "type": "integer", - "details": { - "type": "uint256", - "index": 0, - "indexed": true - } - }, - "numbers": { - "type": "array", - "details": { - "type": "uint256[]", - "index": 1 - }, - "items": { - "type": "integer", - "details": { - "type": "uint256" - } - } - } - } - }`), - }, - }, - Returns: []*core.FFIParam{}, - } - - expectedABIElement := abi.Entry{ - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "widget", - Type: "tuple", - Indexed: false, - Components: abi.ParameterArray{ - { - Name: "radius", - Type: "uint256", - Indexed: true, - InternalType: "", - }, - { - Name: "numbers", - Type: "uint256[]", - Indexed: false, - InternalType: "", - }, - }, - }, - }, - Outputs: abi.ParameterArray{}, - } - - abi, err := e.FFIMethodToABI(context.Background(), method, nil) - assert.NoError(t, err) - assert.ObjectsAreEqual(expectedABIElement, abi) -} - -func TestABIFFIConversionArrayOfObjects(t *testing.T) { - e, _ := newTestEthereum() - - abiJSON := `[ - { - "inputs": [ - { - "components": [ - { - "internalType": "string", - "name": "name", - "type": "string" - }, - { - "internalType": "uint256", - "name": "weight", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "volume", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "string", - "name": "name", - "type": "string" - }, - { - "internalType": "string", - "name": "description", - "type": "string" - }, - { - "internalType": "enum ComplexStorage.Alignment", - "name": "alignment", - "type": "uint8" - } - ], - "internalType": "struct ComplexStorage.BoxContent[]", - "name": "contents", - "type": "tuple[]" - } - ], - "internalType": "struct ComplexStorage.Box[]", - "name": "newBox", - "type": "tuple[]" - } - ], - "name": "set", - "outputs": [], - "stateMutability": "payable", - "type": "function", - "payable": true, - "constant": true - } - ]` - - var abi *abi.ABI - json.Unmarshal([]byte(abiJSON), &abi) - abiFunction := abi.Functions()["set"] - - ffiMethod, err := e.convertABIFunctionToFFIMethod(context.Background(), abiFunction) - assert.NoError(t, err) - abiFunctionOut, err := e.FFIMethodToABI(context.Background(), ffiMethod, nil) - assert.NoError(t, err) - - expectedABIFunctionJSON, err := json.Marshal(abiFunction) - assert.NoError(t, err) - abiFunctionJSON, err := json.Marshal(abiFunctionOut) - assert.NoError(t, err) - assert.JSONEq(t, string(expectedABIFunctionJSON), string(abiFunctionJSON)) - -} - -func TestFFIMethodToABINestedArray(t *testing.T) { - e, _ := newTestEthereum() - - method := &core.FFIMethod{ - Name: "set", - Params: []*core.FFIParam{ - { - Name: "widget", - Schema: fftypes.JSONAnyPtr(`{ - "type": "array", - "details": { - "type": "string[][]", - "internalType": "string[][]" - }, - "items": { - "type": "array", - "items": { - "type": "string" - } - } - }`), - }, - }, - Returns: []*core.FFIParam{}, - } - - expectedABIElement := &abi.Entry{ - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "widget", - Type: "string[][]", - InternalType: "string[][]", - Indexed: false, - }, - }, - Outputs: abi.ParameterArray{}, - } - - abi, err := e.FFIMethodToABI(context.Background(), method, nil) - assert.NoError(t, err) - expectedABIJSON, err := json.Marshal(expectedABIElement) - assert.NoError(t, err) - abiJSON, err := json.Marshal(abi) - assert.NoError(t, err) - assert.JSONEq(t, string(expectedABIJSON), string(abiJSON)) -} - -func TestFFIMethodToABIInvalidJSON(t *testing.T) { - e, _ := newTestEthereum() - - method := &core.FFIMethod{ - Name: "set", - Params: []*core.FFIParam{ - { - Name: "newValue", - Schema: fftypes.JSONAnyPtr(`{#!`), - }, - }, - Returns: []*core.FFIParam{}, - } - - _, err := e.FFIMethodToABI(context.Background(), method, nil) - assert.Regexp(t, "invalid json", err) -} - -func TestFFIMethodToABIBadSchema(t *testing.T) { - e, _ := newTestEthereum() - - method := &core.FFIMethod{ - Name: "set", - Params: []*core.FFIParam{ - { - Name: "newValue", - Schema: fftypes.JSONAnyPtr(`{ - "type": "integer", - "detailz": { - "type": "uint256" - } - }`), - }, - }, - Returns: []*core.FFIParam{}, - } - - _, err := e.FFIMethodToABI(context.Background(), method, nil) - assert.Regexp(t, "compilation failed", err) -} - -func TestFFIMethodToABIBadReturn(t *testing.T) { - e, _ := newTestEthereum() - - method := &core.FFIMethod{ - Name: "set", - Params: []*core.FFIParam{}, - Returns: []*core.FFIParam{ - { - Name: "newValue", - Schema: fftypes.JSONAnyPtr(`{ - "type": "integer", - "detailz": { - "type": "uint256" - } - }`), - }, - }, - } - - _, err := e.FFIMethodToABI(context.Background(), method, nil) - assert.Regexp(t, "compilation failed", err) -} - -func TestConvertABIToFFI(t *testing.T) { - e, _ := newTestEthereum() - - abi := &abi.ABI{ - { - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "newValue", - Type: "uint256", - InternalType: "uint256", - }, - }, - Outputs: abi.ParameterArray{}, - }, - { - Name: "get", - Type: "function", - Inputs: abi.ParameterArray{}, - Outputs: abi.ParameterArray{ - { - Name: "value", - Type: "uint256", - InternalType: "uint256", - }, - }, - }, - { - Name: "Updated", - Type: "event", - Inputs: abi.ParameterArray{{ - Name: "value", - Type: "uint256", - InternalType: "uint256", - }}, - Outputs: abi.ParameterArray{}, - }, - } - - schema := fftypes.JSONAnyPtr(`{"type":"integer","details":{"type":"uint256","internalType":"uint256"}}`) - - expectedFFI := &core.FFI{ - Name: "SimpleStorage", - Version: "v0.0.1", - Namespace: "default", - Description: "desc", - Methods: []*core.FFIMethod{ - { - Name: "set", - Params: core.FFIParams{ - { - Name: "newValue", - Schema: schema, - }, - }, - Returns: core.FFIParams{}, - }, - { - Name: "get", - Params: core.FFIParams{}, - Returns: core.FFIParams{ - { - Name: "value", - Schema: schema, - }, - }, - }, - }, - Events: []*core.FFIEvent{ - { - FFIEventDefinition: core.FFIEventDefinition{ - Name: "Updated", - Params: core.FFIParams{ - { - Name: "value", - Schema: schema, - }, - }, - }, - }, - }, - } - - actualFFI, err := e.convertABIToFFI(context.Background(), "default", "SimpleStorage", "v0.0.1", "desc", abi) - assert.NoError(t, err) - assert.NotNil(t, actualFFI) - assert.ObjectsAreEqual(expectedFFI, actualFFI) -} - -func TestConvertABIToFFIWithObject(t *testing.T) { - e, _ := newTestEthereum() - - abi := &abi.ABI{ - &abi.Entry{ - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "newValue", - Type: "tuple", - InternalType: "struct WidgetFactory.Widget", - Components: abi.ParameterArray{ - { - Name: "size", - Type: "uint256", - InternalType: "uint256", - }, - { - Name: "description", - Type: "string", - InternalType: "string", - }, - }, - }, - }, - Outputs: abi.ParameterArray{}, - }, - } - - bigIntDesc := i18n.Expand(context.Background(), coremsgs.APIIntegerDescription) - schema := fftypes.JSONAnyPtr(fmt.Sprintf(`{"type":"object","details":{"type":"tuple","internalType":"struct WidgetFactory.Widget"},"properties":{"description":{"type":"string","details":{"type":"string","internalType":"string","index":1}},"size":{"oneOf":[{"type":"string"},{"type":"integer"}],"details":{"type":"uint256","internalType":"uint256","index":0},"description":"%s"}}}`, bigIntDesc)) - - expectedFFI := &core.FFI{ - Name: "WidgetTest", - Version: "v0.0.1", - Namespace: "default", - Description: "desc", - Methods: []*core.FFIMethod{ - { - Name: "set", - Params: core.FFIParams{ - { - Name: "newValue", - Schema: schema, - }, - }, - Returns: core.FFIParams{}, - Details: map[string]interface{}{}, - }, - }, - Events: []*core.FFIEvent{}, - } - - actualFFI, err := e.convertABIToFFI(context.Background(), "default", "WidgetTest", "v0.0.1", "desc", abi) - assert.NoError(t, err) - assert.NotNil(t, actualFFI) - - expectedFFIJSON, err := json.Marshal(expectedFFI) - assert.NoError(t, err) - actualFFIJSON, err := json.Marshal(actualFFI) - assert.NoError(t, err) - assert.JSONEq(t, string(expectedFFIJSON), string(actualFFIJSON)) - -} - -func TestConvertABIToFFIWithArray(t *testing.T) { - e, _ := newTestEthereum() - - abi := &abi.ABI{ - { - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "newValue", - Type: "string[]", - InternalType: "string[]", - }, - }, - Outputs: abi.ParameterArray{}, - }, - } - - schema := fftypes.JSONAnyPtr(`{"type":"array","details":{"type":"string[]","internalType":"string[]"},"items":{"type":"string"}}`) - - expectedFFI := &core.FFI{ - Name: "WidgetTest", - Version: "v0.0.1", - Namespace: "default", - Description: "desc", - Methods: []*core.FFIMethod{ - { - Name: "set", - Params: core.FFIParams{ - { - Name: "newValue", - Schema: schema, - }, - }, - Returns: core.FFIParams{}, - Details: map[string]interface{}{}, - }, - }, - Events: []*core.FFIEvent{}, - } - - actualFFI, err := e.convertABIToFFI(context.Background(), "default", "WidgetTest", "v0.0.1", "desc", abi) - assert.NoError(t, err) - assert.NotNil(t, actualFFI) - - expectedFFIJSON, err := json.Marshal(expectedFFI) - assert.NoError(t, err) - actualFFIJSON, err := json.Marshal(actualFFI) - assert.NoError(t, err) - assert.JSONEq(t, string(expectedFFIJSON), string(actualFFIJSON)) -} - -func TestConvertABIToFFIWithNestedArray(t *testing.T) { - e, _ := newTestEthereum() - - abi := &abi.ABI{ - { - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - Name: "newValue", - Type: "uint256[][]", - InternalType: "uint256[][]", - }, - }, - Outputs: abi.ParameterArray{}, - }, - } - - schema := fftypes.JSONAnyPtr(`{"type":"array","details":{"type":"uint256[][]","internalType":"uint256[][]"},"items":{"type":"array","items":{"oneOf":[{"type":"string"},{"type":"integer"}],"description":"An integer. You are recommended to use a JSON string. A JSON number can be used for values up to the safe maximum."}}}`) - expectedFFI := &core.FFI{ - Name: "WidgetTest", - Version: "v0.0.1", - Namespace: "default", - Description: "desc", - Methods: []*core.FFIMethod{ - { - Name: "set", - Params: core.FFIParams{ - { - Name: "newValue", - Schema: schema, - }, - }, - Returns: core.FFIParams{}, - Details: map[string]interface{}{}, - }, - }, - Events: []*core.FFIEvent{}, - } - - actualFFI, err := e.convertABIToFFI(context.Background(), "default", "WidgetTest", "v0.0.1", "desc", abi) - assert.NoError(t, err) - assert.NotNil(t, actualFFI) - expectedFFIJSON, err := json.Marshal(expectedFFI) - assert.NoError(t, err) - actualFFIJSON, err := json.Marshal(actualFFI) - assert.NoError(t, err) - assert.JSONEq(t, string(expectedFFIJSON), string(actualFFIJSON)) -} - -func TestConvertABIToFFIWithNestedArrayOfObjects(t *testing.T) { - e, _ := newTestEthereum() - - abi := &abi.ABI{ - { - Name: "set", - Type: "function", - Inputs: abi.ParameterArray{ - { - InternalType: "struct WidgetFactory.Widget[][]", - Name: "gears", - Type: "tuple[][]", - Components: abi.ParameterArray{ - { - InternalType: "string", - Name: "description", - Type: "string", - }, - { - InternalType: "uint256", - Name: "size", - Type: "uint256", - }, - { - InternalType: "bool", - Name: "inUse", - Type: "bool", - }, - }, - }, - }, - Outputs: abi.ParameterArray{}, - }, - } - - bigIntDesc := i18n.Expand(context.Background(), coremsgs.APIIntegerDescription) - schema := fftypes.JSONAnyPtr(fmt.Sprintf(`{"type":"array","details":{"type":"tuple[][]","internalType":"struct WidgetFactory.Widget[][]"},"items":{"type":"array","items":{"type":"object","properties":{"description":{"type":"string","details":{"type":"string","internalType":"string","index":0}},"inUse":{"type":"boolean","details":{"type":"bool","internalType":"bool","index":2}},"size":{"oneOf":[{"type":"string"},{"type":"integer"}],"details":{"type":"uint256","internalType":"uint256","index":1},"description":"%s"}}}}}`, bigIntDesc)) - expectedFFI := &core.FFI{ - Name: "WidgetTest", - Version: "v0.0.1", - Namespace: "default", - Description: "desc", - Methods: []*core.FFIMethod{ - { - Name: "set", - Params: core.FFIParams{ - { - Name: "gears", - Schema: schema, - }, - }, - Returns: core.FFIParams{}, - Details: map[string]interface{}{}, - }, - }, - Events: []*core.FFIEvent{}, - } - - actualFFI, err := e.convertABIToFFI(context.Background(), "default", "WidgetTest", "v0.0.1", "desc", abi) - assert.NoError(t, err) - assert.NotNil(t, actualFFI) - expectedFFIJSON, err := json.Marshal(expectedFFI) - assert.NoError(t, err) - actualFFIJSON, err := json.Marshal(actualFFI) - assert.NoError(t, err) - assert.JSONEq(t, string(expectedFFIJSON), string(actualFFIJSON)) -} - func TestGenerateFFI(t *testing.T) { e, _ := newTestEthereum() - _, err := e.GenerateFFI(context.Background(), &core.FFIGenerationRequest{ + _, err := e.GenerateFFI(context.Background(), &fftypes.FFIGenerationRequest{ Name: "Simple", Version: "v0.0.1", Description: "desc", @@ -2922,7 +2292,7 @@ func TestGenerateFFI(t *testing.T) { func TestGenerateFFIInlineNamespace(t *testing.T) { e, _ := newTestEthereum() - ffi, err := e.GenerateFFI(context.Background(), &core.FFIGenerationRequest{ + ffi, err := e.GenerateFFI(context.Background(), &fftypes.FFIGenerationRequest{ Name: "Simple", Version: "v0.0.1", Description: "desc", @@ -2935,7 +2305,7 @@ func TestGenerateFFIInlineNamespace(t *testing.T) { func TestGenerateFFIEmptyABI(t *testing.T) { e, _ := newTestEthereum() - _, err := e.GenerateFFI(context.Background(), &core.FFIGenerationRequest{ + _, err := e.GenerateFFI(context.Background(), &fftypes.FFIGenerationRequest{ Name: "Simple", Version: "v0.0.1", Description: "desc", @@ -2946,7 +2316,7 @@ func TestGenerateFFIEmptyABI(t *testing.T) { func TestGenerateFFIBadABI(t *testing.T) { e, _ := newTestEthereum() - _, err := e.GenerateFFI(context.Background(), &core.FFIGenerationRequest{ + _, err := e.GenerateFFI(context.Background(), &fftypes.FFIGenerationRequest{ Name: "Simple", Version: "v0.0.1", Description: "desc", @@ -2955,17 +2325,6 @@ func TestGenerateFFIBadABI(t *testing.T) { assert.Regexp(t, "FF10346", err) } -func TestGetFFIType(t *testing.T) { - e, _ := newTestEthereum() - assert.Equal(t, core.FFIInputTypeString, e.getFFIType("string")) - assert.Equal(t, core.FFIInputTypeString, e.getFFIType("address")) - assert.Equal(t, core.FFIInputTypeString, e.getFFIType("byte")) - assert.Equal(t, core.FFIInputTypeBoolean, e.getFFIType("bool")) - assert.Equal(t, core.FFIInputTypeInteger, e.getFFIType("uint256")) - assert.Equal(t, core.FFIInputTypeObject, e.getFFIType("tuple")) - assert.Equal(t, fftypes.FFEnumValue("", ""), e.getFFIType("foobar")) -} - func TestGenerateEventSignature(t *testing.T) { e, _ := newTestEthereum() complexParam := fftypes.JSONObject{ @@ -2991,9 +2350,9 @@ func TestGenerateEventSignature(t *testing.T) { }, }.String() - event := &core.FFIEventDefinition{ + event := &fftypes.FFIEventDefinition{ Name: "Changed", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -3015,9 +2374,9 @@ func TestGenerateEventSignature(t *testing.T) { func TestGenerateEventSignatureInvalid(t *testing.T) { e, _ := newTestEthereum() - event := &core.FFIEventDefinition{ + event := &fftypes.FFIEventDefinition{ Name: "Changed", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"!bad": "bad"`), @@ -3141,116 +2500,15 @@ func TestHandleNetworkActionFail(t *testing.T) { em.AssertExpectations(t) } -func TestConvertABIToFFIBadInputType(t *testing.T) { - e, _ := newTestEthereum() - - abiJSON := `[ - { - "inputs": [ - { - "internalType": "string", - "name": "name", - "type": "foobar" - } - ], - "name": "set", - "outputs": [], - "stateMutability": "payable", - "type": "function", - "payable": true, - "constant": true - } - ]` - - var abi *abi.ABI - json.Unmarshal([]byte(abiJSON), &abi) - _, err := e.convertABIToFFI(context.Background(), "ns1", "name", "version", "description", abi) - assert.Regexp(t, "FF22025", err) -} - -func TestConvertABIToFFIBadOutputType(t *testing.T) { - e, _ := newTestEthereum() - - abiJSON := `[ - { - "outputs": [ - { - "internalType": "string", - "name": "name", - "type": "foobar" - } - ], - "name": "set", - "stateMutability": "viewable", - "type": "function" - } - ]` - - var abi *abi.ABI - json.Unmarshal([]byte(abiJSON), &abi) - _, err := e.convertABIToFFI(context.Background(), "ns1", "name", "version", "description", abi) - assert.Regexp(t, "FF22025", err) -} - -func TestConvertABIToFFIBadEventType(t *testing.T) { +func TestNetworkVersion(t *testing.T) { e, _ := newTestEthereum() - - abiJSON := `[ - { - "inputs": [ - { - "internalType": "string", - "name": "name", - "type": "foobar" - } - ], - "name": "set", - "type": "event" - } - ]` - - var abi *abi.ABI - json.Unmarshal([]byte(abiJSON), &abi) - _, err := e.convertABIToFFI(context.Background(), "ns1", "name", "version", "description", abi) - assert.Regexp(t, "FF22025", err) + e.fireflyContract.networkVersion = 2 + assert.Equal(t, 2, e.NetworkVersion()) } -func TestConvertABIEventFFIEvent(t *testing.T) { +func TestGetFFIParamValidator(t *testing.T) { e, _ := newTestEthereum() - - abiJSON := `[ - { - "inputs": [ - { - "internalType": "string", - "name": "name", - "type": "string" - } - ], - "name": "set", - "type": "event", - "anonymous": true - } - ]` - - var abi *abi.ABI - json.Unmarshal([]byte(abiJSON), &abi) - ffi, err := e.convertABIToFFI(context.Background(), "ns1", "name", "version", "description", abi) - assert.NoError(t, err) - - actualABIEvent, err := e.FFIEventDefinitionToABI(context.Background(), &ffi.Events[0].FFIEventDefinition) - assert.NoError(t, err) - - expectedABIEventJSON, err := json.Marshal(abi.Events()["set"]) - assert.NoError(t, err) - actualABIEventJSON, err := json.Marshal(actualABIEvent) + v, err := e.GetFFIParamValidator(context.Background()) assert.NoError(t, err) - - assert.JSONEq(t, string(expectedABIEventJSON), string(actualABIEventJSON)) -} - -func TestNetworkVersion(t *testing.T) { - e, _ := newTestEthereum() - e.fireflyContract.networkVersion = 2 - assert.Equal(t, 2, e.NetworkVersion()) + assert.NotNil(t, v) } diff --git a/internal/blockchain/ethereum/ffi_param_validator.go b/internal/blockchain/ethereum/ffi_param_validator.go deleted file mode 100644 index 898b94e2ac..0000000000 --- a/internal/blockchain/ethereum/ffi_param_validator.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ethereum - -import ( - "fmt" - "regexp" - "strconv" - "strings" - - "github.com/santhosh-tekuri/jsonschema/v5" -) - -type FFIParamValidator struct{} - -var intRegex, _ = regexp.Compile("^u?int([0-9]{1,3})$") -var bytesRegex, _ = regexp.Compile("^bytes([0-9]{1,2})?") - -func (v *FFIParamValidator) Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error) { - valid := true - if details, ok := m["details"]; ok { - var jsonTypeString string - n, _ := details.(map[string]interface{}) - blockchainType := n["type"].(string) - jsonType, ok := m["type"] - if ok { - jsonTypeString = jsonType.(string) - } else { - _, ok := m["oneOf"] - if ok { - jsonTypeString = integerType - } - } - switch jsonTypeString { - case stringType: - if blockchainType != stringType && - blockchainType != addressType && - !isEthereumNumberType(blockchainType) && - !isEthereumBytesType(blockchainType) { - valid = false - } - case integerType: - if !isEthereumNumberType(blockchainType) { - valid = false - } - case booleanType: - if blockchainType != boolType { - valid = false - } - case arrayType: - if !strings.HasSuffix(blockchainType, "[]") { - valid = false - } - case objectType: - if blockchainType != tupleType { - valid = false - } - } - - if valid { - return detailsSchema(n), nil - } - return nil, fmt.Errorf("cannot cast %v to %v", jsonType, blockchainType) - } - return nil, nil -} - -func (v *FFIParamValidator) GetMetaSchema() *jsonschema.Schema { - return jsonschema.MustCompileString("ffiParamDetails.json", `{ - "$ref": "#/$defs/ethereumParam", - "$defs": { - "ethereumParam": { - "oneOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "not": { - "const": "object" - } - }, - "details": { - "$ref": "#/$defs/details" - } - }, - "required": [ - "details" - ] - }, - { - "type": "object", - "properties": { - "type": { - "const": "object" - }, - "details": { - "$ref": "#/$defs/details" - }, - "properties": { - "type": "object", - "patternProperties": { - ".*": { - "$ref": "#/$defs/ethereumObjectChildParam" - } - } - } - }, - "required": [ - "details", - "type" - ] - } - ] - }, - "ethereumObjectChildParam": { - "oneOf": [ - { - "type": "object", - "properties": { - "type": { - "type": "string", - "not": { - "const": "object" - } - }, - "details": { - "$ref": "#/$defs/objectFieldDetails" - } - }, - "required": [ - "details" - ] - }, - { - "type": "object", - "properties": { - "type": { - "const": "object" - }, - "details": { - "$ref": "#/$defs/objectFieldDetails" - }, - "properties": { - "type": "object", - "patternProperties": { - ".*": { - "$ref": "#/$defs/ethereumObjectChildParam" - } - } - } - }, - "required": [ - "details" - ] - } - ] - }, - "details": { - "type": "object", - "properties": { - "type": { - "type": "string" - }, - "internalType": { - "type": "string" - }, - "indexed": { - "type": "boolean" - } - }, - "required": [ - "type" - ] - }, - "objectFieldDetails": { - "type": "object", - "properties": { - "type": { - "type": "string" - }, - "internalType": { - "type": "string" - }, - "indexed": { - "type": "boolean" - }, - "index": { - "type": "integer" - } - }, - "required": [ - "type", - "index" - ] - } - } - }`) -} - -func (v *FFIParamValidator) GetExtensionName() string { - return "details" -} - -type detailsSchema map[string]interface{} - -func (s detailsSchema) Validate(ctx jsonschema.ValidationContext, v interface{}) error { - // TODO: Additional validation of actual input possible in the future - return nil -} - -func isEthereumNumberType(input string) bool { - matches := intRegex.FindStringSubmatch(input) - if len(matches) == 2 { - i, err := strconv.ParseInt(matches[1], 10, 0) - if err == nil && i >= 8 && i <= 256 && i%8 == 0 { - // valid - return true - } - } - return false -} - -func isEthereumBytesType(input string) bool { - matches := bytesRegex.FindStringSubmatch(input) - if len(matches) == 2 { - if matches[1] == "" { - return true - } - i, err := strconv.ParseInt(matches[1], 10, 0) - if err == nil && i >= 1 && i <= 32 { - // valid - return true - } - } - return false -} diff --git a/internal/blockchain/ethereum/ffi_param_validator_test.go b/internal/blockchain/ethereum/ffi_param_validator_test.go deleted file mode 100644 index 4f740b334c..0000000000 --- a/internal/blockchain/ethereum/ffi_param_validator_test.go +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ethereum - -import ( - "context" - "encoding/json" - "strings" - "testing" - - "github.com/hyperledger/firefly/pkg/core" - "github.com/santhosh-tekuri/jsonschema/v5" - "github.com/stretchr/testify/assert" -) - -func NewTestSchema(input string) (*jsonschema.Schema, error) { - c := jsonschema.NewCompiler() - c.Draft = jsonschema.Draft2020 - f := core.BaseFFIParamValidator{} - c.RegisterExtension(f.GetExtensionName(), f.GetMetaSchema(), f) - e, _ := newTestEthereum() - v, err := e.GetFFIParamValidator(context.Background()) - if err != nil { - return nil, err - } - c.RegisterExtension(v.GetExtensionName(), v.GetMetaSchema(), v) - err = c.AddResource("schema.json", strings.NewReader(input)) - if err != nil { - return nil, err - } - return c.Compile("schema.json") -} - -func jsonDecode(input string) interface{} { - var output interface{} - json.Unmarshal([]byte(input), &output) - return output -} - -func TestSchemaValid(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "integer", - "details": { - "type": "uint256" - } -}`) - assert.NoError(t, err) -} - -func TestSchemaValidBytes(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "string", - "details": { - "type": "bytes" - } -}`) - assert.NoError(t, err) -} - -func TestSchemaValidBytes32(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "string", - "details": { - "type": "bytes32" - } -}`) - assert.NoError(t, err) -} - -func TestSchemaTypeInvalid(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "foobar", - "details": { - "type": "uint256" - } -}`) - assert.Regexp(t, "'/type' does not validate", err) -} - -func TestSchemaTypeInvalidFFIType(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "number", - "details": { - "type": "uint256" - } -}`) - assert.Regexp(t, "oneOf failed", err) -} - -func TestSchemaTypeMissing(t *testing.T) { - _, err := NewTestSchema(`{}`) - assert.Regexp(t, "compilation failed", err) -} - -func TestSchemaDetailsTypeMissing(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "string", - "details": { - "indexed": true - } -}`) - assert.Regexp(t, "compilation failed", err) -} - -func TestSchemaDetailsIndexedWrongType(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "string", - "details": { - "type": "string", - "indexed": "string" - } -}`) - assert.Regexp(t, "compilation failed", err) -} - -func TestSchemaTypeMismatch(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "string", - "details": { - "type": "boolean" - } -}`) - assert.Regexp(t, "cannot cast string to boolean", err) -} - -func TestSchemaTypeMismatchArray(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "array", - "details": { - "type": "string" - } -}`) - assert.Regexp(t, "cannot cast array to string", err) -} - -func TestSchemaTypeMismatchObject(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "object", - "details": { - "type": "string" - } -}`) - assert.Regexp(t, "cannot cast object to string", err) -} - -func TestInputString(t *testing.T) { - s, err := NewTestSchema(` -{ - "type": "string", - "details": { - "type": "string" - } -}`) - assert.NoError(t, err) - err = s.Validate(`"banana"`) - assert.NoError(t, err) -} - -func TestInputInteger(t *testing.T) { - s, err := NewTestSchema(` -{ - "type": "integer", - "details": { - "type": "uint256" - } -}`) - assert.NoError(t, err) - err = s.Validate(1) - assert.NoError(t, err) -} - -func TestInputBoolean(t *testing.T) { - s, err := NewTestSchema(` -{ - "type": "boolean", - "details": { - "type": "bool" - } -}`) - assert.NoError(t, err) - err = s.Validate(true) - assert.NoError(t, err) -} - -func TestInputStruct(t *testing.T) { - s, err := NewTestSchema(` -{ - "type": "object", - "details": { - "type": "tuple" - }, - "properties": { - "x": { - "type": "integer", - "details": { - "type": "uint8", - "index": 0 - } - }, - "y": { - "type": "integer", - "details": { - "type": "uint8", - "index": 1 - } - }, - "z": { - "type": "integer", - "details": { - "type": "uint8", - "index": 2 - } - } - }, - "required": ["x", "y", "z"] -}`) - - input := `{ - "x": 123, - "y": 456, - "z": 789 -}` - - assert.NoError(t, err) - err = s.Validate(jsonDecode(input)) - assert.NoError(t, err) -} - -func TestInputArray(t *testing.T) { - s, err := NewTestSchema(` -{ - "type": "array", - "details": { - "type": "uint8[]" - }, - "items": { - "type": "integer" - } -}`) - - input := `[123,456,789]` - - assert.NoError(t, err) - err = s.Validate(jsonDecode(input)) - assert.NoError(t, err) -} - -func TestInputInvalidBlockchainType(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "boolean", - "details": { - "type": "foobar" - } -}`) - assert.Regexp(t, "cannot cast boolean to foobar", err) -} - -func TestInputInvalidNestedBlockchainType(t *testing.T) { - _, err := NewTestSchema(` -{ - "type": "object", - "details": { - "type": "tuple" - }, - "properties": { - "amount": { - "type": "integer", - "details": { - "type": "string", - "index": 0 - } - } - } -}`) - assert.Regexp(t, "cannot cast integer to string", err) -} - -func TestInputInvalidOneOf(t *testing.T) { - _, err := NewTestSchema(` - { - "oneOf": "banana", - "details": { - "type": "uint256", - "internalType": "uint256" - } - }`) - assert.Regexp(t, "'/oneOf' does not validate", err) -} - -func TestInputInvalidOneOfType(t *testing.T) { - _, err := NewTestSchema(` - { - "oneOf": [ - { - "type": "banana" - } - ], - "details": { - "type": "uint256", - "internalType": "uint256" - } - }`) - assert.Regexp(t, "'/oneOf/0/type' does not validate", err) -} - -func TestInputNoAdditionalProperties(t *testing.T) { - s, err := NewTestSchema(` -{ - "type": "object", - "details": { - "type": "tuple" - }, - "properties": { - "foo": { - "type": "string", - "details": { - "type": "string", - "index": 0 - } - } - }, - "additionalProperties": false -}`) - - input := `{ - "foo": "foo", - "bar": "bar" -}` - - assert.NoError(t, err) - err = s.Validate(jsonDecode(input)) - assert.Regexp(t, "additionalProperties 'bar' not allowed", err) -} diff --git a/internal/blockchain/fabric/fabric.go b/internal/blockchain/fabric/fabric.go index efea17ce18..767b614a92 100644 --- a/internal/blockchain/fabric/fabric.go +++ b/internal/blockchain/fabric/fabric.go @@ -743,7 +743,7 @@ func (f *Fabric) buildFabconnectRequestBody(ctx context.Context, channel, chainc return body, nil } -func (f *Fabric) InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) error { +func (f *Fabric) InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) error { fabricOnChainLocation, err := parseContractLocation(ctx, location) if err != nil { return err @@ -766,7 +766,7 @@ func (f *Fabric) InvokeContract(ctx context.Context, nsOpID string, signingKey s return f.invokeContractMethod(ctx, fabricOnChainLocation.Channel, fabricOnChainLocation.Chaincode, method.Name, signingKey, nsOpID, prefixItems, input, options) } -func (f *Fabric) QueryContract(ctx context.Context, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) { +func (f *Fabric) QueryContract(ctx context.Context, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) { fabricOnChainLocation, err := parseContractLocation(ctx, location) if err != nil { return nil, err @@ -853,16 +853,16 @@ func (f *Fabric) DeleteContractListener(ctx context.Context, subscription *core. return f.streams.deleteSubscription(ctx, subscription.BackendID) } -func (f *Fabric) GetFFIParamValidator(ctx context.Context) (core.FFIParamValidator, error) { +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 } -func (f *Fabric) GenerateFFI(ctx context.Context, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) { +func (f *Fabric) GenerateFFI(ctx context.Context, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) { return nil, i18n.NewError(ctx, coremsgs.MsgFFIGenerationUnsupported) } -func (f *Fabric) GenerateEventSignature(ctx context.Context, event *core.FFIEventDefinition) string { +func (f *Fabric) GenerateEventSignature(ctx context.Context, event *fftypes.FFIEventDefinition) string { return event.Name } diff --git a/internal/blockchain/fabric/fabric_test.go b/internal/blockchain/fabric/fabric_test.go index e8ea554b67..7c4dfa3732 100644 --- a/internal/blockchain/fabric/fabric_test.go +++ b/internal/blockchain/fabric/fabric_test.go @@ -73,10 +73,10 @@ func newTestFabric() (*Fabric, func()) { } } -func testFFIMethod() *core.FFIMethod { - return &core.FFIMethod{ +func testFFIMethod() *fftypes.FFIMethod { + return &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -90,7 +90,7 @@ func testFFIMethod() *core.FFIMethod { Schema: fftypes.JSONAnyPtr(`{"type": "string"}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -1694,15 +1694,15 @@ func TestInvokeContractBadSchema(t *testing.T) { Channel: "firefly", Chaincode: "simplestorage", } - method := &core.FFIMethod{ + method := &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{not json]`), }, }, - Returns: []*core.FFIParam{}, + Returns: []*fftypes.FFIParam{}, } params := map[string]interface{}{ "x": float64(1), @@ -1973,7 +1973,7 @@ func TestGetFFIParamValidator(t *testing.T) { func TestGenerateFFI(t *testing.T) { e, _ := newTestFabric() - _, err := e.GenerateFFI(context.Background(), &core.FFIGenerationRequest{ + _, err := e.GenerateFFI(context.Background(), &fftypes.FFIGenerationRequest{ Name: "Simple", Version: "v0.0.1", Description: "desc", @@ -1984,7 +1984,7 @@ func TestGenerateFFI(t *testing.T) { func TestGenerateEventSignature(t *testing.T) { e, _ := newTestFabric() - signature := e.GenerateEventSignature(context.Background(), &core.FFIEventDefinition{Name: "Changed"}) + signature := e.GenerateEventSignature(context.Background(), &fftypes.FFIEventDefinition{Name: "Changed"}) assert.Equal(t, "Changed", signature) } diff --git a/internal/contracts/manager.go b/internal/contracts/manager.go index 396cdb6e78..428faa02d9 100644 --- a/internal/contracts/manager.go +++ b/internal/contracts/manager.go @@ -38,21 +38,21 @@ import ( type Manager interface { core.Named - BroadcastFFI(ctx context.Context, ns string, ffi *core.FFI, waitConfirm bool) (output *core.FFI, err error) - GetFFI(ctx context.Context, ns, name, version string) (*core.FFI, error) - GetFFIWithChildren(ctx context.Context, ns, name, version string) (*core.FFI, error) - GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) - GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) - GetFFIs(ctx context.Context, ns string, filter database.AndFilter) ([]*core.FFI, *database.FilterResult, error) + BroadcastFFI(ctx context.Context, ns string, ffi *fftypes.FFI, waitConfirm bool) (output *fftypes.FFI, err error) + GetFFI(ctx context.Context, ns, name, version string) (*fftypes.FFI, error) + GetFFIWithChildren(ctx context.Context, ns, name, version string) (*fftypes.FFI, error) + GetFFIByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) + GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) + GetFFIs(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.FFI, *database.FilterResult, error) InvokeContract(ctx context.Context, ns string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) InvokeContractAPI(ctx context.Context, ns, apiName, methodPath string, req *core.ContractCallRequest, waitConfirm bool) (interface{}, error) GetContractAPI(ctx context.Context, httpServerURL, ns, apiName string) (*core.ContractAPI, error) - GetContractAPIInterface(ctx context.Context, ns, apiName string) (*core.FFI, error) + GetContractAPIInterface(ctx context.Context, ns, apiName string) (*fftypes.FFI, error) GetContractAPIs(ctx context.Context, httpServerURL, ns string, filter database.AndFilter) ([]*core.ContractAPI, *database.FilterResult, error) BroadcastContractAPI(ctx context.Context, httpServerURL, ns string, api *core.ContractAPI, waitConfirm bool) (output *core.ContractAPI, err error) - ValidateFFIAndSetPathnames(ctx context.Context, ffi *core.FFI) error + ValidateFFIAndSetPathnames(ctx context.Context, ffi *fftypes.FFI) error AddContractListener(ctx context.Context, ns string, listener *core.ContractListenerInput) (output *core.ContractListener, err error) AddContractAPIListener(ctx context.Context, ns, apiName, eventPath string, listener *core.ContractListener) (output *core.ContractListener, err error) @@ -60,7 +60,7 @@ type Manager interface { GetContractListeners(ctx context.Context, ns string, filter database.AndFilter) ([]*core.ContractListener, *database.FilterResult, error) GetContractAPIListeners(ctx context.Context, ns string, apiName, eventPath string, filter database.AndFilter) ([]*core.ContractListener, *database.FilterResult, error) DeleteContractListenerByNameOrID(ctx context.Context, ns, nameOrID string) error - GenerateFFI(ctx context.Context, ns string, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) + GenerateFFI(ctx context.Context, ns string, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) // From operations.OperationHandler PrepareOperation(ctx context.Context, op *core.Operation) (*core.PreparedOperation, error) @@ -73,7 +73,7 @@ type contractManager struct { broadcast broadcast.Manager identity identity.Manager blockchain blockchain.Plugin - ffiParamValidator core.FFIParamValidator + ffiParamValidator fftypes.FFIParamValidator operations operations.Manager syncasync syncasync.Bridge } @@ -110,14 +110,14 @@ func (cm *contractManager) Name() string { } func (cm *contractManager) newFFISchemaCompiler() *jsonschema.Compiler { - c := core.NewFFISchemaCompiler() + c := fftypes.NewFFISchemaCompiler() if cm.ffiParamValidator != nil { c.RegisterExtension(cm.ffiParamValidator.GetExtensionName(), cm.ffiParamValidator.GetMetaSchema(), cm.ffiParamValidator) } return c } -func (cm *contractManager) BroadcastFFI(ctx context.Context, ns string, ffi *core.FFI, waitConfirm bool) (output *core.FFI, err error) { +func (cm *contractManager) BroadcastFFI(ctx context.Context, ns string, ffi *fftypes.FFI, waitConfirm bool) (output *fftypes.FFI, err error) { ffi.ID = fftypes.NewUUID() ffi.Namespace = ns @@ -149,11 +149,11 @@ func (cm *contractManager) scopeNS(ns string, filter database.AndFilter) databas return filter.Condition(filter.Builder().Eq("namespace", ns)) } -func (cm *contractManager) GetFFI(ctx context.Context, ns, name, version string) (*core.FFI, error) { +func (cm *contractManager) GetFFI(ctx context.Context, ns, name, version string) (*fftypes.FFI, error) { return cm.database.GetFFI(ctx, ns, name, version) } -func (cm *contractManager) GetFFIWithChildren(ctx context.Context, ns, name, version string) (*core.FFI, error) { +func (cm *contractManager) GetFFIWithChildren(ctx context.Context, ns, name, version string) (*fftypes.FFI, error) { ffi, err := cm.GetFFI(ctx, ns, name, version) if err == nil { err = cm.getFFIChildren(ctx, ffi) @@ -161,11 +161,11 @@ func (cm *contractManager) GetFFIWithChildren(ctx context.Context, ns, name, ver return ffi, err } -func (cm *contractManager) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) { +func (cm *contractManager) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) { return cm.database.GetFFIByID(ctx, id) } -func (cm *contractManager) getFFIChildren(ctx context.Context, ffi *core.FFI) (err error) { +func (cm *contractManager) getFFIChildren(ctx context.Context, ffi *fftypes.FFI) (err error) { mfb := database.FFIMethodQueryFactory.NewFilter(ctx) ffi.Methods, _, err = cm.database.GetFFIMethods(ctx, mfb.Eq("interface", ffi.ID)) if err != nil { @@ -184,7 +184,7 @@ func (cm *contractManager) getFFIChildren(ctx context.Context, ffi *core.FFI) (e return nil } -func (cm *contractManager) GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (ffi *core.FFI, err error) { +func (cm *contractManager) GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (ffi *fftypes.FFI, err error) { err = cm.database.RunAsGroup(ctx, func(ctx context.Context) (err error) { ffi, err = cm.database.GetFFIByID(ctx, id) if err != nil || ffi == nil { @@ -195,7 +195,7 @@ func (cm *contractManager) GetFFIByIDWithChildren(ctx context.Context, id *fftyp return ffi, err } -func (cm *contractManager) GetFFIs(ctx context.Context, ns string, filter database.AndFilter) ([]*core.FFI, *database.FilterResult, error) { +func (cm *contractManager) GetFFIs(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.FFI, *database.FilterResult, error) { filter = cm.scopeNS(ns, filter) return cm.database.GetFFIs(ctx, ns, filter) } @@ -304,7 +304,7 @@ func (cm *contractManager) GetContractAPI(ctx context.Context, httpServerURL, ns return api, err } -func (cm *contractManager) GetContractAPIInterface(ctx context.Context, ns, apiName string) (*core.FFI, error) { +func (cm *contractManager) GetContractAPIInterface(ctx context.Context, ns, apiName string) (*fftypes.FFI, error) { api, err := cm.GetContractAPI(ctx, "", ns, apiName) if err != nil || api == nil { return nil, err @@ -321,7 +321,7 @@ func (cm *contractManager) GetContractAPIs(ctx context.Context, httpServerURL, n return apis, fr, err } -func (cm *contractManager) resolveFFIReference(ctx context.Context, ns string, ref *core.FFIReference) error { +func (cm *contractManager) resolveFFIReference(ctx context.Context, ns string, ref *fftypes.FFIReference) error { switch { case ref == nil: return i18n.NewError(ctx, coremsgs.MsgContractInterfaceNotFound, "") @@ -398,7 +398,7 @@ func (cm *contractManager) uniquePathName(name string, usedNames map[string]bool } } -func (cm *contractManager) ValidateFFIAndSetPathnames(ctx context.Context, ffi *core.FFI) error { +func (cm *contractManager) ValidateFFIAndSetPathnames(ctx context.Context, ffi *fftypes.FFI) error { if err := ffi.Validate(ctx, false); err != nil { return err } @@ -425,7 +425,7 @@ func (cm *contractManager) ValidateFFIAndSetPathnames(ctx context.Context, ffi * return nil } -func (cm *contractManager) validateFFIMethod(ctx context.Context, method *core.FFIMethod) error { +func (cm *contractManager) validateFFIMethod(ctx context.Context, method *fftypes.FFIMethod) error { if method.Name == "" { return i18n.NewError(ctx, coremsgs.MsgMethodNameMustBeSet) } @@ -442,7 +442,7 @@ func (cm *contractManager) validateFFIMethod(ctx context.Context, method *core.F return nil } -func (cm *contractManager) validateFFIParam(ctx context.Context, param *core.FFIParam) error { +func (cm *contractManager) validateFFIParam(ctx context.Context, param *fftypes.FFIParam) error { c := cm.newFFISchemaCompiler() if err := c.AddResource(param.Name, strings.NewReader(param.Schema.String())); err != nil { return i18n.WrapError(ctx, err, coremsgs.MsgFFISchemaParseFail, param.Name) @@ -453,7 +453,7 @@ func (cm *contractManager) validateFFIParam(ctx context.Context, param *core.FFI return nil } -func (cm *contractManager) validateFFIEvent(ctx context.Context, event *core.FFIEventDefinition) error { +func (cm *contractManager) validateFFIEvent(ctx context.Context, event *fftypes.FFIEventDefinition) error { if event.Name == "" { return i18n.NewError(ctx, coremsgs.MsgEventNameMustBeSet) } @@ -483,7 +483,7 @@ func (cm *contractManager) validateInvokeContractRequest(ctx context.Context, re return nil } -func (cm *contractManager) resolveEvent(ctx context.Context, ns string, ffi *core.FFIReference, eventPath string) (*core.FFISerializedEvent, error) { +func (cm *contractManager) resolveEvent(ctx context.Context, ns string, ffi *fftypes.FFIReference, eventPath string) (*core.FFISerializedEvent, error) { if err := cm.resolveFFIReference(ctx, ns, ffi); err != nil { return nil, err } @@ -500,15 +500,15 @@ func (cm *contractManager) AddContractListener(ctx context.Context, ns string, l listener.ID = fftypes.NewUUID() listener.Namespace = ns - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return nil, err } if listener.Name != "" { - if err := core.ValidateFFNameField(ctx, listener.Name, "name"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, listener.Name, "name"); err != nil { return nil, err } } - if err := core.ValidateFFNameField(ctx, listener.Topic, "topic"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, listener.Topic, "topic"); err != nil { return nil, err } if listener.Location, err = cm.blockchain.NormalizeContractLocation(ctx, listener.Location); err != nil { @@ -587,7 +587,7 @@ func (cm *contractManager) AddContractAPIListener(ctx context.Context, ns, apiNa } input := &core.ContractListenerInput{ContractListener: *listener} - input.Interface = &core.FFIReference{ID: api.Interface.ID} + input.Interface = &fftypes.FFIReference{ID: api.Interface.ID} input.EventPath = eventPath if api.Location != nil { input.Location = api.Location @@ -599,7 +599,7 @@ func (cm *contractManager) AddContractAPIListener(ctx context.Context, ns, apiNa func (cm *contractManager) GetContractListenerByNameOrID(ctx context.Context, ns, nameOrID string) (listener *core.ContractListener, err error) { id, err := fftypes.ParseUUID(ctx, nameOrID) if err != nil { - if err := core.ValidateFFNameField(ctx, nameOrID, "name"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, nameOrID, "name"); err != nil { return nil, err } if listener, err = cm.database.GetContractListener(ctx, ns, nameOrID); err != nil { @@ -656,7 +656,7 @@ func (cm *contractManager) DeleteContractListenerByNameOrID(ctx context.Context, }) } -func (cm *contractManager) checkParamSchema(ctx context.Context, input interface{}, param *core.FFIParam) error { +func (cm *contractManager) checkParamSchema(ctx context.Context, input interface{}, param *fftypes.FFIParam) error { // TODO: Cache the compiled schema? c := jsonschema.NewCompiler() err := c.AddResource(param.Name, strings.NewReader(param.Schema.String())) @@ -673,7 +673,7 @@ func (cm *contractManager) checkParamSchema(ctx context.Context, input interface return nil } -func (cm *contractManager) GenerateFFI(ctx context.Context, ns string, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) { +func (cm *contractManager) GenerateFFI(ctx context.Context, ns string, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) { generationRequest.Namespace = ns return cm.blockchain.GenerateFFI(ctx, generationRequest) } diff --git a/internal/contracts/manager_test.go b/internal/contracts/manager_test.go index 40ee242068..ee52e796ce 100644 --- a/internal/contracts/manager_test.go +++ b/internal/contracts/manager_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/hyperledger/firefly/internal/blockchain/ethereum" + "github.com/hyperledger/firefly-signer/pkg/ffi" "github.com/hyperledger/firefly/internal/identity" "github.com/hyperledger/firefly/internal/syncasync" "github.com/hyperledger/firefly/internal/txcommon" @@ -99,7 +99,7 @@ func TestNewContractManagerFFISchemaLoader(t *testing.T) { mom := &operationmocks.Manager{} txHelper := txcommon.NewTransactionHelper(mdi, mdm) msa := &syncasyncmocks.Bridge{} - mbi.On("GetFFIParamValidator", mock.Anything).Return(ðereum.FFIParamValidator{}, nil) + mbi.On("GetFFIParamValidator", mock.Anything).Return(&ffi.ParamValidator{}, nil) mom.On("RegisterHandler", mock.Anything, mock.Anything, mock.Anything) _, err := NewContractManager(context.Background(), mdi, mbm, mim, mbi, mom, txHelper, msa) assert.NoError(t, err) @@ -119,19 +119,19 @@ func TestBroadcastFFI(t *testing.T) { ID: fftypes.NewUUID(), }, } - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) - ffi := &core.FFI{ + mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) + ffi := &fftypes.FFI{ Name: "test", Version: "1.0.0", ID: fftypes.NewUUID(), - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", }, }, @@ -153,15 +153,15 @@ func TestBroadcastFFIInvalid(t *testing.T) { ID: fftypes.NewUUID(), }, } - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) - ffi := &core.FFI{ + mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) + ffi := &fftypes.FFI{ Name: "test", Version: "1.0.0", ID: fftypes.NewUUID(), - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "number"}`), @@ -179,15 +179,15 @@ func TestBroadcastFFIExists(t *testing.T) { mdb := cm.database.(*databasemocks.Plugin) mbm := cm.broadcast.(*broadcastmocks.Manager) - mdb.On("GetFFI", mock.Anything, "ns1", "test", "1.0.0").Return(&core.FFI{}, nil) + mdb.On("GetFFI", mock.Anything, "ns1", "test", "1.0.0").Return(&fftypes.FFI{}, nil) msg := &core.Message{ Header: core.MessageHeader{ ID: fftypes.NewUUID(), }, } - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) - ffi := &core.FFI{ + mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.FFI"), core.SystemTagDefineFFI, false).Return(msg, nil) + ffi := &fftypes.FFI{ Name: "test", Version: "1.0.0", ID: fftypes.NewUUID(), @@ -205,12 +205,12 @@ func TestBroadcastFFIFail(t *testing.T) { mdb.On("GetFFI", mock.Anything, "ns1", "test", "1.0.0").Return(nil, nil) mim.On("GetOrgKey", mock.Anything).Return("key", nil) - mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.FFI"), core.SystemTagDefineFFI, false).Return(nil, fmt.Errorf("pop")) - ffi := &core.FFI{ + mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.FFI"), core.SystemTagDefineFFI, false).Return(nil, fmt.Errorf("pop")) + ffi := &fftypes.FFI{ Name: "test", Version: "1.0.0", ID: fftypes.NewUUID(), - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", }, @@ -224,9 +224,9 @@ func TestValidateInvokeContractRequest(t *testing.T) { cm := newTestContractManager() req := &core.ContractCallRequest{ Type: core.CallTypeInvoke, - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -236,7 +236,7 @@ func TestValidateInvokeContractRequest(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -256,9 +256,9 @@ func TestValidateInvokeContractRequestMissingInput(t *testing.T) { cm := newTestContractManager() req := &core.ContractCallRequest{ Type: core.CallTypeInvoke, - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -268,7 +268,7 @@ func TestValidateInvokeContractRequestMissingInput(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -287,9 +287,9 @@ func TestValidateInvokeContractRequestInputWrongType(t *testing.T) { cm := newTestContractManager() req := &core.ContractCallRequest{ Type: core.CallTypeInvoke, - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -299,7 +299,7 @@ func TestValidateInvokeContractRequestInputWrongType(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -319,9 +319,9 @@ func TestValidateInvokeContractRequestInvalidParam(t *testing.T) { cm := newTestContractManager() req := &core.ContractCallRequest{ Type: core.CallTypeInvoke, - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -331,7 +331,7 @@ func TestValidateInvokeContractRequestInvalidParam(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "number"}`), @@ -350,14 +350,14 @@ func TestValidateInvokeContractRequestInvalidParam(t *testing.T) { func TestValidateFFI(t *testing.T) { cm := newTestContractManager() - ffi := &core.FFI{ + ffi := &fftypes.FFI{ Name: "math", Version: "1.0.0", Namespace: "default", - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -367,7 +367,7 @@ func TestValidateFFI(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -377,15 +377,15 @@ func TestValidateFFI(t *testing.T) { { Name: "sum", Description: "Override of sum method with different args", - Params: []*core.FFIParam{}, - Returns: []*core.FFIParam{}, + Params: []*fftypes.FFIParam{}, + Returns: []*fftypes.FFIParam{}, }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -394,10 +394,10 @@ func TestValidateFFI(t *testing.T) { }, }, { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "sum", Description: "Override of event with different params", - Params: []*core.FFIParam{}, + Params: []*fftypes.FFIParam{}, }, }, }, @@ -414,12 +414,12 @@ func TestValidateFFI(t *testing.T) { func TestValidateFFIFail(t *testing.T) { cm := newTestContractManager() - ffi := &core.FFI{ + ffi := &fftypes.FFI{ Namespace: "default", - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -429,7 +429,7 @@ func TestValidateFFIFail(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -439,15 +439,15 @@ func TestValidateFFIFail(t *testing.T) { { Name: "sum", Description: "Override of sum method with different args", - Params: []*core.FFIParam{}, - Returns: []*core.FFIParam{}, + Params: []*fftypes.FFIParam{}, + Returns: []*fftypes.FFIParam{}, }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -456,10 +456,10 @@ func TestValidateFFIFail(t *testing.T) { }, }, { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "sum", Description: "Override of event with different params", - Params: []*core.FFIParam{}, + Params: []*fftypes.FFIParam{}, }, }, }, @@ -471,14 +471,14 @@ func TestValidateFFIFail(t *testing.T) { func TestValidateFFIBadMethod(t *testing.T) { cm := newTestContractManager() - ffi := &core.FFI{ + ffi := &fftypes.FFI{ Name: "math", Version: "1.0.0", Namespace: "default", - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -488,7 +488,7 @@ func TestValidateFFIBadMethod(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -496,11 +496,11 @@ func TestValidateFFIBadMethod(t *testing.T) { }, }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -517,14 +517,14 @@ func TestValidateFFIBadMethod(t *testing.T) { func TestValidateFFIBadEventParam(t *testing.T) { cm := newTestContractManager() - ffi := &core.FFI{ + ffi := &fftypes.FFI{ Name: "math", Version: "1.0.0", Namespace: "default", - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -534,7 +534,7 @@ func TestValidateFFIBadEventParam(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: []*core.FFIParam{ + Returns: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -542,11 +542,11 @@ func TestValidateFFIBadEventParam(t *testing.T) { }, }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "", - Params: []*core.FFIParam{ + Params: []*fftypes.FFIParam{ { Name: "z", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -572,9 +572,9 @@ func TestAddContractListenerInline(t *testing.T) { "address": "0x123", }.String()), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -609,12 +609,12 @@ func TestAddContractListenerByEventPath(t *testing.T) { interfaceID := fftypes.NewUUID() - event := &core.FFIEvent{ + event := &fftypes.FFIEvent{ ID: fftypes.NewUUID(), Namespace: "ns1", - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -625,7 +625,7 @@ func TestAddContractListenerByEventPath(t *testing.T) { sub := &core.ContractListenerInput{ ContractListener: core.ContractListener{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -640,7 +640,7 @@ func TestAddContractListenerByEventPath(t *testing.T) { mbi.On("GenerateEventSignature", context.Background(), mock.Anything).Return("changed") mdi.On("GetContractListeners", context.Background(), mock.Anything).Return(nil, nil, nil) mbi.On("AddContractListener", context.Background(), sub).Return(nil) - mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&core.FFI{}, nil) + mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&fftypes.FFI{}, nil) mdi.On("GetFFIEvent", context.Background(), "ns1", interfaceID, sub.EventPath).Return(event, nil) mdi.On("InsertContractListener", context.Background(), &sub.ContractListener).Return(nil) @@ -659,7 +659,7 @@ func TestAddContractListenerBadLocation(t *testing.T) { sub := &core.ContractListenerInput{ ContractListener: core.ContractListener{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -687,7 +687,7 @@ func TestAddContractListenerFFILookupFail(t *testing.T) { sub := &core.ContractListenerInput{ ContractListener: core.ContractListener{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -717,7 +717,7 @@ func TestAddContractListenerEventLookupFail(t *testing.T) { sub := &core.ContractListenerInput{ ContractListener: core.ContractListener{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -729,7 +729,7 @@ func TestAddContractListenerEventLookupFail(t *testing.T) { } mbi.On("NormalizeContractLocation", context.Background(), sub.Location).Return(sub.Location, nil) - mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&core.FFI{}, nil) + mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&fftypes.FFI{}, nil) mdi.On("GetFFIEvent", context.Background(), "ns1", interfaceID, sub.EventPath).Return(nil, fmt.Errorf("pop")) _, err := cm.AddContractListener(context.Background(), "ns1", sub) @@ -748,7 +748,7 @@ func TestAddContractListenerEventLookupNotFound(t *testing.T) { sub := &core.ContractListenerInput{ ContractListener: core.ContractListener{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -760,7 +760,7 @@ func TestAddContractListenerEventLookupNotFound(t *testing.T) { } mbi.On("NormalizeContractLocation", context.Background(), sub.Location).Return(sub.Location, nil) - mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&core.FFI{}, nil) + mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&fftypes.FFI{}, nil) mdi.On("GetFFIEvent", context.Background(), "ns1", interfaceID, sub.EventPath).Return(nil, nil) _, err := cm.AddContractListener(context.Background(), "ns1", sub) @@ -936,9 +936,9 @@ func TestAddContractListenerValidateFail(t *testing.T) { "address": "0x123", }.String()), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "number"}`), @@ -972,9 +972,9 @@ func TestAddContractListenerBlockchainFail(t *testing.T) { "address": "0x123", }.String()), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -1009,9 +1009,9 @@ func TestAddContractListenerUpsertSubFail(t *testing.T) { "address": "0x123", }.String()), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -1043,7 +1043,7 @@ func TestAddContractAPIListener(t *testing.T) { interfaceID := fftypes.NewUUID() api := &core.ContractAPI{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -1053,15 +1053,15 @@ func TestAddContractAPIListener(t *testing.T) { listener := &core.ContractListener{ Topic: "test-topic", } - event := &core.FFIEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + event := &fftypes.FFIEvent{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", }, } mdi.On("GetContractAPIByName", context.Background(), "ns", "simple").Return(api, nil) mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(listener.Location, nil) - mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&core.FFI{}, nil) + mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&fftypes.FFI{}, nil) mdi.On("GetFFIEvent", context.Background(), "ns", interfaceID, "changed").Return(event, nil) mbi.On("GenerateEventSignature", context.Background(), mock.Anything).Return("changed") mdi.On("GetContractListeners", context.Background(), mock.Anything).Return(nil, nil, nil) @@ -1120,7 +1120,7 @@ func TestAddContractAPIListenerFail(t *testing.T) { func TestGetFFI(t *testing.T) { cm := newTestContractManager() mdb := cm.database.(*databasemocks.Plugin) - mdb.On("GetFFI", mock.Anything, "ns1", "ffi", "v1.0.0").Return(&core.FFI{}, nil) + mdb.On("GetFFI", mock.Anything, "ns1", "ffi", "v1.0.0").Return(&fftypes.FFI{}, nil) _, err := cm.GetFFI(context.Background(), "ns1", "ffi", "v1.0.0") assert.NoError(t, err) } @@ -1131,14 +1131,14 @@ func TestGetFFIWithChildren(t *testing.T) { mbi := cm.blockchain.(*blockchainmocks.Plugin) cid := fftypes.NewUUID() - mdb.On("GetFFI", mock.Anything, "ns1", "ffi", "v1.0.0").Return(&core.FFI{ID: cid}, nil) - mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*core.FFIMethod{ + mdb.On("GetFFI", mock.Anything, "ns1", "ffi", "v1.0.0").Return(&fftypes.FFI{ID: cid}, nil) + mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*fftypes.FFIMethod{ {ID: fftypes.NewUUID(), Name: "method1"}, }, nil, nil) - mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return([]*core.FFIEvent{ - {ID: fftypes.NewUUID(), FFIEventDefinition: core.FFIEventDefinition{Name: "event1"}}, + mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return([]*fftypes.FFIEvent{ + {ID: fftypes.NewUUID(), FFIEventDefinition: fftypes.FFIEventDefinition{Name: "event1"}}, }, nil, nil) - mbi.On("GenerateEventSignature", mock.Anything, mock.MatchedBy(func(ev *core.FFIEventDefinition) bool { + mbi.On("GenerateEventSignature", mock.Anything, mock.MatchedBy(func(ev *fftypes.FFIEventDefinition) bool { return ev.Name == "event1" })).Return("event1Sig") @@ -1153,7 +1153,7 @@ func TestGetFFIByID(t *testing.T) { cm := newTestContractManager() mdb := cm.database.(*databasemocks.Plugin) cid := fftypes.NewUUID() - mdb.On("GetFFIByID", mock.Anything, cid).Return(&core.FFI{}, nil) + mdb.On("GetFFIByID", mock.Anything, cid).Return(&fftypes.FFI{}, nil) _, err := cm.GetFFIByID(context.Background(), cid) assert.NoError(t, err) } @@ -1164,16 +1164,16 @@ func TestGetFFIByIDWithChildren(t *testing.T) { mbi := cm.blockchain.(*blockchainmocks.Plugin) cid := fftypes.NewUUID() - mdb.On("GetFFIByID", mock.Anything, cid).Return(&core.FFI{ + mdb.On("GetFFIByID", mock.Anything, cid).Return(&fftypes.FFI{ ID: cid, }, nil) - mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*core.FFIMethod{ + mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*fftypes.FFIMethod{ {ID: fftypes.NewUUID(), Name: "method1"}, }, nil, nil) - mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return([]*core.FFIEvent{ - {ID: fftypes.NewUUID(), FFIEventDefinition: core.FFIEventDefinition{Name: "event1"}}, + mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return([]*fftypes.FFIEvent{ + {ID: fftypes.NewUUID(), FFIEventDefinition: fftypes.FFIEventDefinition{Name: "event1"}}, }, nil, nil) - mbi.On("GenerateEventSignature", mock.Anything, mock.MatchedBy(func(ev *core.FFIEventDefinition) bool { + mbi.On("GenerateEventSignature", mock.Anything, mock.MatchedBy(func(ev *fftypes.FFIEventDefinition) bool { return ev.Name == "event1" })).Return("event1Sig") @@ -1192,10 +1192,10 @@ func TestGetFFIByIDWithChildrenEventsFail(t *testing.T) { mdb := cm.database.(*databasemocks.Plugin) cid := fftypes.NewUUID() - mdb.On("GetFFIByID", mock.Anything, cid).Return(&core.FFI{ + mdb.On("GetFFIByID", mock.Anything, cid).Return(&fftypes.FFI{ ID: cid, }, nil) - mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*core.FFIMethod{ + mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*fftypes.FFIMethod{ {ID: fftypes.NewUUID(), Name: "method1"}, }, nil, nil) mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return(nil, nil, fmt.Errorf("pop")) @@ -1211,7 +1211,7 @@ func TestGetFFIByIDWithChildrenMethodsFail(t *testing.T) { mdb := cm.database.(*databasemocks.Plugin) cid := fftypes.NewUUID() - mdb.On("GetFFIByID", mock.Anything, cid).Return(&core.FFI{ + mdb.On("GetFFIByID", mock.Anything, cid).Return(&fftypes.FFI{ ID: cid, }, nil) mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return(nil, nil, fmt.Errorf("pop")) @@ -1253,7 +1253,7 @@ func TestGetFFIs(t *testing.T) { cm := newTestContractManager() mdb := cm.database.(*databasemocks.Plugin) filter := database.FFIQueryFactory.NewFilter(context.Background()).And() - mdb.On("GetFFIs", mock.Anything, "ns1", filter).Return([]*core.FFI{}, &database.FilterResult{}, nil) + mdb.On("GetFFIs", mock.Anything, "ns1", filter).Return([]*fftypes.FFI{}, &database.FilterResult{}, nil) _, _, err := cm.GetFFIs(context.Background(), "ns1", filter) assert.NoError(t, err) } @@ -1269,11 +1269,11 @@ func TestInvokeContract(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "doStuff", ID: fftypes.NewUUID(), - Params: core.FFIParams{}, - Returns: core.FFIParams{}, + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{}, }, } @@ -1309,11 +1309,11 @@ func TestInvokeContractConfirm(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "doStuff", ID: fftypes.NewUUID(), - Params: core.FFIParams{}, - Returns: core.FFIParams{}, + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{}, }, } @@ -1355,11 +1355,11 @@ func TestInvokeContractFail(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "doStuff", ID: fftypes.NewUUID(), - Params: core.FFIParams{}, - Returns: core.FFIParams{}, + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{}, }, } @@ -1428,11 +1428,11 @@ func TestInvokeContractTXFail(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "doStuff", ID: fftypes.NewUUID(), - Params: core.FFIParams{}, - Returns: core.FFIParams{}, + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{}, }, } @@ -1472,9 +1472,9 @@ func TestInvokeContractMethodBadInput(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "sum", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -1484,7 +1484,7 @@ func TestInvokeContractMethodBadInput(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: core.FFIParams{ + Returns: fftypes.FFIParams{ { Name: "sum", @@ -1510,11 +1510,11 @@ func TestQueryContract(t *testing.T) { Type: core.CallTypeQuery, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "doStuff", ID: fftypes.NewUUID(), - Params: core.FFIParams{}, - Returns: core.FFIParams{}, + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{}, }, } @@ -1539,11 +1539,11 @@ func TestCallContractInvalidType(t *testing.T) { req := &core.ContractCallRequest{ Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "doStuff", ID: fftypes.NewUUID(), - Params: core.FFIParams{}, - Returns: core.FFIParams{}, + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{}, }, } @@ -1635,21 +1635,21 @@ func TestGetContractAPIListeners(t *testing.T) { interfaceID := fftypes.NewUUID() api := &core.ContractAPI{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ "address": "0x123", }.String()), } - event := &core.FFIEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + event := &fftypes.FFIEvent{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "changed", }, } mdi.On("GetContractAPIByName", context.Background(), "ns", "simple").Return(api, nil) - mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&core.FFI{}, nil) + mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&fftypes.FFI{}, nil) mdi.On("GetFFIEvent", context.Background(), "ns", interfaceID, "changed").Return(event, nil) mbi.On("GenerateEventSignature", context.Background(), mock.Anything).Return("changed") mdi.On("GetContractListeners", context.Background(), mock.Anything).Return(nil, nil, nil) @@ -1694,7 +1694,7 @@ func TestGetContractAPIListenersEventNotFound(t *testing.T) { interfaceID := fftypes.NewUUID() api := &core.ContractAPI{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, }, Location: fftypes.JSONAnyPtr(fftypes.JSONObject{ @@ -1703,7 +1703,7 @@ func TestGetContractAPIListenersEventNotFound(t *testing.T) { } mdi.On("GetContractAPIByName", context.Background(), "ns", "simple").Return(api, nil) - mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&core.FFI{}, nil) + mdi.On("GetFFIByID", context.Background(), interfaceID).Return(&fftypes.FFI{}, nil) mdi.On("GetFFIEvent", context.Background(), "ns", interfaceID, "changed").Return(nil, nil) f := database.ContractListenerQueryFactory.NewFilter(context.Background()) @@ -1769,14 +1769,14 @@ func TestInvokeContractAPI(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ ID: fftypes.NewUUID(), Name: "peel", }, } api := &core.ContractAPI{ - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, Location: fftypes.JSONAnyPtr(""), @@ -1812,7 +1812,7 @@ func TestInvokeContractAPIFailContractLookup(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ ID: fftypes.NewUUID(), }, } @@ -1833,7 +1833,7 @@ func TestInvokeContractAPIContractNotFound(t *testing.T) { Type: core.CallTypeInvoke, Interface: fftypes.NewUUID(), Location: fftypes.JSONAnyPtr(""), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ ID: fftypes.NewUUID(), }, } @@ -1893,18 +1893,18 @@ func TestGetContractAPIInterface(t *testing.T) { api := &core.ContractAPI{ Namespace: "ns1", Name: "banana", - Interface: &core.FFIReference{ID: interfaceID}, + Interface: &fftypes.FFIReference{ID: interfaceID}, } mdb.On("GetContractAPIByName", mock.Anything, "ns1", "banana").Return(api, nil) - mdb.On("GetFFIByID", mock.Anything, interfaceID).Return(&core.FFI{}, nil) - mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*core.FFIMethod{ + mdb.On("GetFFIByID", mock.Anything, interfaceID).Return(&fftypes.FFI{}, nil) + mdb.On("GetFFIMethods", mock.Anything, mock.Anything).Return([]*fftypes.FFIMethod{ {ID: fftypes.NewUUID(), Name: "method1"}, }, nil, nil) - mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return([]*core.FFIEvent{ - {ID: fftypes.NewUUID(), FFIEventDefinition: core.FFIEventDefinition{Name: "event1"}}, + mdb.On("GetFFIEvents", mock.Anything, mock.Anything).Return([]*fftypes.FFIEvent{ + {ID: fftypes.NewUUID(), FFIEventDefinition: fftypes.FFIEventDefinition{Name: "event1"}}, }, nil, nil) - mbi.On("GenerateEventSignature", mock.Anything, mock.MatchedBy(func(ev *core.FFIEventDefinition) bool { + mbi.On("GenerateEventSignature", mock.Anything, mock.MatchedBy(func(ev *fftypes.FFIEventDefinition) bool { return ev.Name == "event1" })).Return("event1Sig") @@ -1946,14 +1946,14 @@ func TestBroadcastContractAPI(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) - mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&core.FFI{}, nil) + mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) api, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) @@ -1977,7 +1977,7 @@ func TestBroadcastContractAPIBadLocation(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -2008,7 +2008,7 @@ func TestBroadcastContractAPIExisting(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -2017,14 +2017,14 @@ func TestBroadcastContractAPIExisting(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(existing, nil) - mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&core.FFI{}, nil) + mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) @@ -2047,7 +2047,7 @@ func TestBroadcastContractAPICannotChangeLocation(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(`"old"`), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -2056,7 +2056,7 @@ func TestBroadcastContractAPICannotChangeLocation(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(`"new"`), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -2088,7 +2088,7 @@ func TestBroadcastContractAPIInterfaceName(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ Name: "my-ffi", Version: "1", }, @@ -2097,7 +2097,7 @@ func TestBroadcastContractAPIInterfaceName(t *testing.T) { mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) - mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(&core.FFI{ID: interfaceID}, nil) + mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(&fftypes.FFI{ID: interfaceID}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(msg, nil) _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) @@ -2121,14 +2121,14 @@ func TestBroadcastContractAPIFail(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } mbi.On("NormalizeContractLocation", context.Background(), api.Location).Return(api.Location, nil) mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil) - mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&core.FFI{}, nil) + mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil) mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*core.ContractAPI"), core.SystemTagDefineContractAPI, false).Return(nil, fmt.Errorf("pop")) _, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false) @@ -2173,7 +2173,7 @@ func TestBroadcastContractAPIInterfaceIDFail(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -2200,7 +2200,7 @@ func TestBroadcastContractAPIInterfaceIDNotFound(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, } @@ -2227,7 +2227,7 @@ func TestBroadcastContractAPIInterfaceNameFail(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ Name: "my-ffi", Version: "1", }, @@ -2255,7 +2255,7 @@ func TestBroadcastContractAPIInterfaceNameNotFound(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ Name: "my-ffi", Version: "1", }, @@ -2283,7 +2283,7 @@ func TestBroadcastContractAPIInterfaceNoVersion(t *testing.T) { Namespace: "ns1", Location: fftypes.JSONAnyPtr(""), Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ Name: "my-ffi", }, } @@ -2301,7 +2301,7 @@ func TestBroadcastContractAPIInterfaceNoVersion(t *testing.T) { func TestValidateFFIParamBadSchemaJSON(t *testing.T) { cm := newTestContractManager() - param := &core.FFIParam{ + param := &fftypes.FFIParam{ Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer"`), } @@ -2311,7 +2311,7 @@ func TestValidateFFIParamBadSchemaJSON(t *testing.T) { func TestCheckParamSchemaBadSchema(t *testing.T) { cm := newTestContractManager() - param := &core.FFIParam{ + param := &fftypes.FFIParam{ Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer"`), } @@ -2321,7 +2321,7 @@ func TestCheckParamSchemaBadSchema(t *testing.T) { func TestCheckParamSchemaCompileFail(t *testing.T) { cm := newTestContractManager() - param := &core.FFIParam{ + param := &fftypes.FFIParam{ Name: "x", Schema: fftypes.JSONAnyPtr(``), } @@ -2344,10 +2344,10 @@ func TestAddJSONSchemaExtension(t *testing.T) { func TestGenerateFFI(t *testing.T) { cm := newTestContractManager() mbi := cm.blockchain.(*blockchainmocks.Plugin) - mbi.On("GenerateFFI", mock.Anything, mock.Anything).Return(&core.FFI{ + mbi.On("GenerateFFI", mock.Anything, mock.Anything).Return(&fftypes.FFI{ Name: "generated", }, nil) - ffi, err := cm.GenerateFFI(context.Background(), "default", &core.FFIGenerationRequest{}) + ffi, err := cm.GenerateFFI(context.Background(), "default", &fftypes.FFIGenerationRequest{}) assert.NoError(t, err) assert.NotNil(t, ffi) assert.Equal(t, "generated", ffi.Name) diff --git a/internal/contracts/operations_test.go b/internal/contracts/operations_test.go index 25c9cd6fe6..ee244ad454 100644 --- a/internal/contracts/operations_test.go +++ b/internal/contracts/operations_test.go @@ -40,7 +40,7 @@ func TestPrepareAndRunBlockchainInvoke(t *testing.T) { req := &core.ContractCallRequest{ Key: "0x123", Location: fftypes.JSONAnyPtr(`{"address":"0x1111"}`), - Method: &core.FFIMethod{ + Method: &fftypes.FFIMethod{ Name: "set", }, Input: map[string]interface{}{ @@ -53,7 +53,7 @@ func TestPrepareAndRunBlockchainInvoke(t *testing.T) { mbi := cm.blockchain.(*blockchainmocks.Plugin) mbi.On("InvokeContract", context.Background(), "ns1:"+op.ID.String(), "0x123", mock.MatchedBy(func(loc *fftypes.JSONAny) bool { return loc.String() == req.Location.String() - }), mock.MatchedBy(func(method *core.FFIMethod) bool { + }), mock.MatchedBy(func(method *fftypes.FFIMethod) bool { return method.Name == req.Method.Name }), req.Input, req.Options).Return(nil) diff --git a/internal/coremsgs/en_api_translations.go b/internal/coremsgs/en_api_translations.go index df32b05807..d3149d2ec9 100644 --- a/internal/coremsgs/en_api_translations.go +++ b/internal/coremsgs/en_api_translations.go @@ -189,7 +189,6 @@ var ( APIHistogramStartTimeParam = ffm("api.histogramStartTime", "Start time of the data to be fetched") APIHistogramEndTimeParam = ffm("api.histogramEndTime", "End time of the data to be fetched") APIHistogramBucketsParam = ffm("api.histogramBuckets", "Number of buckets between start time and end time") - APIIntegerDescription = ffm("api.integer", "An integer. You are recommended to use a JSON string. A JSON number can be used for values up to the safe maximum.") APISmartContractDetails = ffm("api.smartContractDetails", "Additional smart contract details") APISmartContractDetailsKey = ffm("api.smartContractDetailsKey", "Key") diff --git a/internal/data/blobstore.go b/internal/data/blobstore.go index b5f5e20ce7..9ef458484a 100644 --- a/internal/data/blobstore.go +++ b/internal/data/blobstore.go @@ -144,7 +144,7 @@ func (bs *blobStore) UploadBlob(ctx context.Context, ns string, inData *core.Dat func (bs *blobStore) DownloadBlob(ctx context.Context, ns, dataID string) (*core.Blob, io.ReadCloser, error) { - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return nil, nil, err } id, err := fftypes.ParseUUID(ctx, dataID) diff --git a/internal/data/data_manager.go b/internal/data/data_manager.go index d23d87d504..b176804242 100644 --- a/internal/data/data_manager.go +++ b/internal/data/data_manager.go @@ -158,7 +158,7 @@ func (dm *dataManager) namespaceExistsCached(ctx context.Context, ns string) (bo } func (dm *dataManager) VerifyNamespaceExists(ctx context.Context, ns string) error { - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return err } if exists, err := dm.namespaceExistsCached(ctx, ns); err != nil { diff --git a/internal/database/sqlcommon/contractapis_sql.go b/internal/database/sqlcommon/contractapis_sql.go index 4e5b307521..992ad9bc45 100644 --- a/internal/database/sqlcommon/contractapis_sql.go +++ b/internal/database/sqlcommon/contractapis_sql.go @@ -114,7 +114,7 @@ func (s *SQLCommon) UpsertContractAPI(ctx context.Context, api *core.ContractAPI func (s *SQLCommon) contractAPIResult(ctx context.Context, row *sql.Rows) (*core.ContractAPI, error) { api := core.ContractAPI{ - Interface: &core.FFIReference{}, + Interface: &fftypes.FFIReference{}, } err := row.Scan( &api.ID, diff --git a/internal/database/sqlcommon/contractapis_sql_test.go b/internal/database/sqlcommon/contractapis_sql_test.go index 9a8868697f..f7aa1c7657 100644 --- a/internal/database/sqlcommon/contractapis_sql_test.go +++ b/internal/database/sqlcommon/contractapis_sql_test.go @@ -46,7 +46,7 @@ func TestContractAPIE2EWithDB(t *testing.T) { ID: apiID, Namespace: "ns1", Name: "banana", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: interfaceID, Name: "banana", Version: "v1.0.0", @@ -102,7 +102,7 @@ func TestContractAPIDBFailInsert(t *testing.T) { mock.ExpectQuery("SELECT .*").WillReturnRows(rows) // mock.ExpectQuery("INSERT .*").WillReturnError(fmt.Errorf("pop")) api := &core.ContractAPI{ - Interface: &core.FFIReference{}, + Interface: &fftypes.FFIReference{}, } err := s.UpsertContractAPI(context.Background(), api) assert.Regexp(t, "FF10116", err) @@ -117,7 +117,7 @@ func TestContractAPIDBFailUpdate(t *testing.T) { mock.ExpectQuery("SELECT .*").WillReturnRows(rows) mock.ExpectQuery("UPDATE .*").WillReturnError(fmt.Errorf("pop")) api := &core.ContractAPI{ - Interface: &core.FFIReference{}, + Interface: &fftypes.FFIReference{}, } err := s.UpsertContractAPI(context.Background(), api) assert.Regexp(t, "pop", err) diff --git a/internal/database/sqlcommon/contractlisteners_sql.go b/internal/database/sqlcommon/contractlisteners_sql.go index 47e5fd994b..b8f348eccf 100644 --- a/internal/database/sqlcommon/contractlisteners_sql.go +++ b/internal/database/sqlcommon/contractlisteners_sql.go @@ -93,7 +93,7 @@ func (s *SQLCommon) InsertContractListener(ctx context.Context, listener *core.C func (s *SQLCommon) contractListenerResult(ctx context.Context, row *sql.Rows) (*core.ContractListener, error) { listener := core.ContractListener{ - Interface: &core.FFIReference{}, + Interface: &fftypes.FFIReference{}, } err := row.Scan( &listener.ID, diff --git a/internal/database/sqlcommon/contractlisteners_sql_test.go b/internal/database/sqlcommon/contractlisteners_sql_test.go index fb4c61d8a4..97060a1a54 100644 --- a/internal/database/sqlcommon/contractlisteners_sql_test.go +++ b/internal/database/sqlcommon/contractlisteners_sql_test.go @@ -39,11 +39,11 @@ func TestContractListenerE2EWithDB(t *testing.T) { locationJson, _ := json.Marshal(location) sub := &core.ContractListener{ ID: fftypes.NewUUID(), - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "event1", }, }, diff --git a/internal/database/sqlcommon/ffi_events_sql.go b/internal/database/sqlcommon/ffi_events_sql.go index f3baa90f6c..a09b46d66a 100644 --- a/internal/database/sqlcommon/ffi_events_sql.go +++ b/internal/database/sqlcommon/ffi_events_sql.go @@ -47,7 +47,7 @@ var ( const ffieventsTable = "ffievents" -func (s *SQLCommon) UpsertFFIEvent(ctx context.Context, event *core.FFIEvent) (err error) { +func (s *SQLCommon) UpsertFFIEvent(ctx context.Context, event *fftypes.FFIEvent) (err error) { ctx, tx, autoCommit, err := s.beginOrUseTx(ctx) if err != nil { return err @@ -101,8 +101,8 @@ func (s *SQLCommon) UpsertFFIEvent(ctx context.Context, event *core.FFIEvent) (e return s.commitTx(ctx, tx, autoCommit) } -func (s *SQLCommon) ffiEventResult(ctx context.Context, row *sql.Rows) (*core.FFIEvent, error) { - event := core.FFIEvent{} +func (s *SQLCommon) ffiEventResult(ctx context.Context, row *sql.Rows) (*fftypes.FFIEvent, error) { + event := fftypes.FFIEvent{} err := row.Scan( &event.ID, &event.Interface, @@ -119,7 +119,7 @@ func (s *SQLCommon) ffiEventResult(ctx context.Context, row *sql.Rows) (*core.FF return &event, nil } -func (s *SQLCommon) getFFIEventPred(ctx context.Context, desc string, pred interface{}) (*core.FFIEvent, error) { +func (s *SQLCommon) getFFIEventPred(ctx context.Context, desc string, pred interface{}) (*fftypes.FFIEvent, error) { rows, _, err := s.query(ctx, ffieventsTable, sq.Select(ffiEventsColumns...). From(ffieventsTable). @@ -143,7 +143,7 @@ func (s *SQLCommon) getFFIEventPred(ctx context.Context, desc string, pred inter return ci, nil } -func (s *SQLCommon) GetFFIEvents(ctx context.Context, filter database.Filter) (events []*core.FFIEvent, res *database.FilterResult, err error) { +func (s *SQLCommon) GetFFIEvents(ctx context.Context, filter database.Filter) (events []*fftypes.FFIEvent, res *database.FilterResult, err error) { query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(ffiEventsColumns...).From(ffieventsTable), filter, ffiEventFilterFieldMap, []interface{}{"sequence"}) if err != nil { return nil, nil, err @@ -167,10 +167,10 @@ func (s *SQLCommon) GetFFIEvents(ctx context.Context, filter database.Filter) (e } -func (s *SQLCommon) GetFFIEvent(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*core.FFIEvent, error) { +func (s *SQLCommon) GetFFIEvent(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*fftypes.FFIEvent, error) { return s.getFFIEventPred(ctx, ns+":"+pathName, sq.And{sq.Eq{"namespace": ns}, sq.Eq{"interface_id": interfaceID}, sq.Eq{"pathname": pathName}}) } -func (s *SQLCommon) GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*core.FFIEvent, error) { +func (s *SQLCommon) GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFIEvent, error) { return s.getFFIEventPred(ctx, id.String(), sq.Eq{"id": id}) } diff --git a/internal/database/sqlcommon/ffi_events_sql_test.go b/internal/database/sqlcommon/ffi_events_sql_test.go index 4eefa6c0ae..6ac73bdd90 100644 --- a/internal/database/sqlcommon/ffi_events_sql_test.go +++ b/internal/database/sqlcommon/ffi_events_sql_test.go @@ -38,15 +38,15 @@ func TestFFIEventsE2EWithDB(t *testing.T) { // Create a new event entry interfaceID := fftypes.NewUUID() eventID := fftypes.NewUUID() - event := &core.FFIEvent{ + event := &fftypes.FFIEvent{ ID: eventID, Interface: interfaceID, Namespace: "ns", Pathname: "Changed_1", - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "Changed", Description: "Things changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -83,7 +83,7 @@ func TestFFIEventsE2EWithDB(t *testing.T) { assert.Equal(t, string(eventJson), string(eventReadJson)) // Update event - event.Params = core.FFIParams{} + event.Params = fftypes.FFIParams{} err = s.UpsertFFIEvent(ctx, event) assert.NoError(t, err) @@ -101,7 +101,7 @@ func TestFFIEventsE2EWithDB(t *testing.T) { func TestFFIEventDBFailBeginTransaction(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin().WillReturnError(fmt.Errorf("pop")) - err := s.UpsertFFIEvent(context.Background(), &core.FFIEvent{}) + err := s.UpsertFFIEvent(context.Background(), &fftypes.FFIEvent{}) assert.Regexp(t, "FF10114", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -110,7 +110,7 @@ func TestFFIEventDBFailSelect(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnError(fmt.Errorf("pop")) - err := s.UpsertFFIEvent(context.Background(), &core.FFIEvent{}) + err := s.UpsertFFIEvent(context.Background(), &fftypes.FFIEvent{}) assert.Regexp(t, "pop", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -120,7 +120,7 @@ func TestFFIEventDBFailInsert(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnRows(rows) - event := &core.FFIEvent{ + event := &fftypes.FFIEvent{ ID: fftypes.NewUUID(), } err := s.UpsertFFIEvent(context.Background(), event) @@ -135,7 +135,7 @@ func TestFFIEventDBFailUpdate(t *testing.T) { mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnRows(rows) mock.ExpectQuery("UPDATE .*").WillReturnError(fmt.Errorf("pop")) - event := &core.FFIEvent{ + event := &fftypes.FFIEvent{ ID: fftypes.NewUUID(), } err := s.UpsertFFIEvent(context.Background(), event) diff --git a/internal/database/sqlcommon/ffi_methods_sql.go b/internal/database/sqlcommon/ffi_methods_sql.go index 7363a61a51..f201eab779 100644 --- a/internal/database/sqlcommon/ffi_methods_sql.go +++ b/internal/database/sqlcommon/ffi_methods_sql.go @@ -48,7 +48,7 @@ var ( const ffimethodsTable = "ffimethods" -func (s *SQLCommon) UpsertFFIMethod(ctx context.Context, method *core.FFIMethod) (err error) { +func (s *SQLCommon) UpsertFFIMethod(ctx context.Context, method *fftypes.FFIMethod) (err error) { ctx, tx, autoCommit, err := s.beginOrUseTx(ctx) if err != nil { return err @@ -104,8 +104,8 @@ func (s *SQLCommon) UpsertFFIMethod(ctx context.Context, method *core.FFIMethod) return s.commitTx(ctx, tx, autoCommit) } -func (s *SQLCommon) ffiMethodResult(ctx context.Context, row *sql.Rows) (*core.FFIMethod, error) { - method := core.FFIMethod{} +func (s *SQLCommon) ffiMethodResult(ctx context.Context, row *sql.Rows) (*fftypes.FFIMethod, error) { + method := fftypes.FFIMethod{} err := row.Scan( &method.ID, &method.Interface, @@ -123,7 +123,7 @@ func (s *SQLCommon) ffiMethodResult(ctx context.Context, row *sql.Rows) (*core.F return &method, nil } -func (s *SQLCommon) getFFIMethodPred(ctx context.Context, desc string, pred interface{}) (*core.FFIMethod, error) { +func (s *SQLCommon) getFFIMethodPred(ctx context.Context, desc string, pred interface{}) (*fftypes.FFIMethod, error) { rows, _, err := s.query(ctx, ffimethodsTable, sq.Select(ffiMethodsColumns...). From(ffimethodsTable). @@ -147,7 +147,7 @@ func (s *SQLCommon) getFFIMethodPred(ctx context.Context, desc string, pred inte return ci, nil } -func (s *SQLCommon) GetFFIMethods(ctx context.Context, filter database.Filter) (methods []*core.FFIMethod, res *database.FilterResult, err error) { +func (s *SQLCommon) GetFFIMethods(ctx context.Context, filter database.Filter) (methods []*fftypes.FFIMethod, res *database.FilterResult, err error) { query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(ffiMethodsColumns...).From(ffimethodsTable), filter, ffiMethodFilterFieldMap, []interface{}{"sequence"}) if err != nil { return nil, nil, err @@ -171,6 +171,6 @@ func (s *SQLCommon) GetFFIMethods(ctx context.Context, filter database.Filter) ( } -func (s *SQLCommon) GetFFIMethod(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*core.FFIMethod, error) { +func (s *SQLCommon) GetFFIMethod(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*fftypes.FFIMethod, error) { return s.getFFIMethodPred(ctx, ns+":"+pathName, sq.And{sq.Eq{"namespace": ns}, sq.Eq{"interface_id": interfaceID}, sq.Eq{"pathname": pathName}}) } diff --git a/internal/database/sqlcommon/ffi_methods_sql_test.go b/internal/database/sqlcommon/ffi_methods_sql_test.go index 236b3876f5..93df4e075b 100644 --- a/internal/database/sqlcommon/ffi_methods_sql_test.go +++ b/internal/database/sqlcommon/ffi_methods_sql_test.go @@ -38,20 +38,20 @@ func TestFFIMethodsE2EWithDB(t *testing.T) { // Create a new method entry interfaceID := fftypes.NewUUID() methodID := fftypes.NewUUID() - method := &core.FFIMethod{ + method := &fftypes.FFIMethod{ ID: methodID, Interface: interfaceID, Name: "Set", Namespace: "ns", Pathname: "Set_1", Description: "Sets things", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), }, }, - Returns: core.FFIParams{ + Returns: fftypes.FFIParams{ { Name: "value", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -87,7 +87,7 @@ func TestFFIMethodsE2EWithDB(t *testing.T) { assert.Equal(t, string(methodJson), string(methodReadJson)) // Update method - method.Params = core.FFIParams{} + method.Params = fftypes.FFIParams{} err = s.UpsertFFIMethod(ctx, method) assert.NoError(t, err) @@ -105,7 +105,7 @@ func TestFFIMethodsE2EWithDB(t *testing.T) { func TestFFIMethodDBFailBeginTransaction(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin().WillReturnError(fmt.Errorf("pop")) - err := s.UpsertFFIMethod(context.Background(), &core.FFIMethod{}) + err := s.UpsertFFIMethod(context.Background(), &fftypes.FFIMethod{}) assert.Regexp(t, "FF10114", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -114,7 +114,7 @@ func TestFFIMethodDBFailSelect(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnError(fmt.Errorf("pop")) - err := s.UpsertFFIMethod(context.Background(), &core.FFIMethod{}) + err := s.UpsertFFIMethod(context.Background(), &fftypes.FFIMethod{}) assert.Regexp(t, "pop", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -124,7 +124,7 @@ func TestFFIMethodDBFailInsert(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnRows(rows) - event := &core.FFIMethod{ + event := &fftypes.FFIMethod{ ID: fftypes.NewUUID(), } err := s.UpsertFFIMethod(context.Background(), event) @@ -139,7 +139,7 @@ func TestFFIMethodDBFailUpdate(t *testing.T) { mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnRows(rows) mock.ExpectQuery("UPDATE .*").WillReturnError(fmt.Errorf("pop")) - event := &core.FFIMethod{ + event := &fftypes.FFIMethod{ ID: fftypes.NewUUID(), } err := s.UpsertFFIMethod(context.Background(), event) diff --git a/internal/database/sqlcommon/ffi_sql.go b/internal/database/sqlcommon/ffi_sql.go index e965846645..9822b07d0b 100644 --- a/internal/database/sqlcommon/ffi_sql.go +++ b/internal/database/sqlcommon/ffi_sql.go @@ -45,7 +45,7 @@ var ( const ffiTable = "ffi" -func (s *SQLCommon) UpsertFFI(ctx context.Context, ffi *core.FFI) (err error) { +func (s *SQLCommon) UpsertFFI(ctx context.Context, ffi *fftypes.FFI) (err error) { ctx, tx, autoCommit, err := s.beginOrUseTx(ctx) if err != nil { return err @@ -100,8 +100,8 @@ func (s *SQLCommon) UpsertFFI(ctx context.Context, ffi *core.FFI) (err error) { return s.commitTx(ctx, tx, autoCommit) } -func (s *SQLCommon) ffiResult(ctx context.Context, row *sql.Rows) (*core.FFI, error) { - ffi := core.FFI{} +func (s *SQLCommon) ffiResult(ctx context.Context, row *sql.Rows) (*fftypes.FFI, error) { + ffi := fftypes.FFI{} err := row.Scan( &ffi.ID, &ffi.Namespace, @@ -116,7 +116,7 @@ func (s *SQLCommon) ffiResult(ctx context.Context, row *sql.Rows) (*core.FFI, er return &ffi, nil } -func (s *SQLCommon) getFFIPred(ctx context.Context, desc string, pred interface{}) (*core.FFI, error) { +func (s *SQLCommon) getFFIPred(ctx context.Context, desc string, pred interface{}) (*fftypes.FFI, error) { rows, _, err := s.query(ctx, ffiTable, sq.Select(ffiColumns...). From(ffiTable). @@ -140,7 +140,7 @@ func (s *SQLCommon) getFFIPred(ctx context.Context, desc string, pred interface{ return ffi, nil } -func (s *SQLCommon) GetFFIs(ctx context.Context, ns string, filter database.Filter) (ffis []*core.FFI, res *database.FilterResult, err error) { +func (s *SQLCommon) GetFFIs(ctx context.Context, ns string, filter database.Filter) (ffis []*fftypes.FFI, res *database.FilterResult, err error) { query, fop, fi, err := s.filterSelect(ctx, "", sq.Select(ffiColumns...).From(ffiTable).Where(sq.Eq{"namespace": ns}), filter, ffiFilterFieldMap, []interface{}{"sequence"}) if err != nil { @@ -153,7 +153,7 @@ func (s *SQLCommon) GetFFIs(ctx context.Context, ns string, filter database.Filt } defer rows.Close() - ffis = []*core.FFI{} + ffis = []*fftypes.FFI{} for rows.Next() { cd, err := s.ffiResult(ctx, rows) if err != nil { @@ -166,10 +166,10 @@ func (s *SQLCommon) GetFFIs(ctx context.Context, ns string, filter database.Filt } -func (s *SQLCommon) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) { +func (s *SQLCommon) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) { return s.getFFIPred(ctx, id.String(), sq.Eq{"id": id}) } -func (s *SQLCommon) GetFFI(ctx context.Context, ns, name, version string) (*core.FFI, error) { +func (s *SQLCommon) GetFFI(ctx context.Context, ns, name, version string) (*fftypes.FFI, error) { return s.getFFIPred(ctx, ns+":"+name+":"+version, sq.And{sq.Eq{"namespace": ns}, sq.Eq{"name": name}, sq.Eq{"version": version}}) } diff --git a/internal/database/sqlcommon/ffi_sql_test.go b/internal/database/sqlcommon/ffi_sql_test.go index c25d830d9d..d1dd4dc3a9 100644 --- a/internal/database/sqlcommon/ffi_sql_test.go +++ b/internal/database/sqlcommon/ffi_sql_test.go @@ -39,17 +39,17 @@ func TestFFIE2EWithDB(t *testing.T) { // Create a new FFI id := fftypes.NewUUID() - ffi := &core.FFI{ + ffi := &fftypes.FFI{ ID: id, Namespace: "ns1", Name: "math", Version: "v1.0.0", Description: "Does things and stuff", Message: fftypes.NewUUID(), - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer""}`), @@ -59,7 +59,7 @@ func TestFFIE2EWithDB(t *testing.T) { Schema: fftypes.JSONAnyPtr(`{"type": "integer""}`), }, }, - Returns: core.FFIParams{ + Returns: fftypes.FFIParams{ { Name: "result", Schema: fftypes.JSONAnyPtr(`{"type": "integer""}`), @@ -104,7 +104,7 @@ func TestFFIE2EWithDB(t *testing.T) { func TestFFIDBFailBeginTransaction(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin().WillReturnError(fmt.Errorf("pop")) - err := s.UpsertFFI(context.Background(), &core.FFI{}) + err := s.UpsertFFI(context.Background(), &fftypes.FFI{}) assert.Regexp(t, "FF10114", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -113,7 +113,7 @@ func TestFFIDBFailSelect(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnError(fmt.Errorf("pop")) - err := s.UpsertFFI(context.Background(), &core.FFI{}) + err := s.UpsertFFI(context.Background(), &fftypes.FFI{}) assert.Regexp(t, "pop", err) assert.NoError(t, mock.ExpectationsWereMet()) } @@ -123,7 +123,7 @@ func TestFFIDBFailInsert(t *testing.T) { s, mock := newMockProvider().init() mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnRows(rows) - ffi := &core.FFI{ + ffi := &fftypes.FFI{ ID: fftypes.NewUUID(), } err := s.UpsertFFI(context.Background(), ffi) @@ -138,7 +138,7 @@ func TestFFIDBFailUpdate(t *testing.T) { mock.ExpectBegin() mock.ExpectQuery("SELECT .*").WillReturnRows(rows) mock.ExpectQuery("UPDATE .*").WillReturnError(fmt.Errorf("pop")) - ffi := &core.FFI{ + ffi := &fftypes.FFI{ ID: fftypes.NewUUID(), } err := s.UpsertFFI(context.Background(), ffi) diff --git a/internal/definitions/definition_handler_contracts.go b/internal/definitions/definition_handler_contracts.go index f6bf550c26..08e0b3f3ae 100644 --- a/internal/definitions/definition_handler_contracts.go +++ b/internal/definitions/definition_handler_contracts.go @@ -27,7 +27,7 @@ import ( "github.com/hyperledger/firefly/pkg/database" ) -func (dh *definitionHandlers) persistFFI(ctx context.Context, ffi *core.FFI) (err error) { +func (dh *definitionHandlers) persistFFI(ctx context.Context, ffi *fftypes.FFI) (err error) { if err = dh.contracts.ValidateFFIAndSetPathnames(ctx, ffi); err != nil { log.L(ctx).Warnf("Unable to process FFI %s - validate failed: %s", ffi.ID, err) return nil @@ -77,7 +77,7 @@ func (dh *definitionHandlers) persistContractAPI(ctx context.Context, api *core. func (dh *definitionHandlers) handleFFIBroadcast(ctx context.Context, state DefinitionBatchState, msg *core.Message, data core.DataArray, tx *fftypes.UUID) (HandlerResult, error) { l := log.L(ctx) - var ffi core.FFI + var ffi fftypes.FFI if valid := dh.getSystemBroadcastPayload(ctx, msg, data, &ffi); !valid { return HandlerResult{Action: ActionReject}, i18n.NewError(ctx, coremsgs.MsgDefRejectedBadPayload, "contract interface", msg.Header.ID) } diff --git a/internal/definitions/definition_handler_contracts_test.go b/internal/definitions/definition_handler_contracts_test.go index cba38a7834..019814651c 100644 --- a/internal/definitions/definition_handler_contracts_test.go +++ b/internal/definitions/definition_handler_contracts_test.go @@ -31,16 +31,16 @@ import ( "github.com/stretchr/testify/mock" ) -func testFFI() *core.FFI { - return &core.FFI{ +func testFFI() *fftypes.FFI { + return &fftypes.FFI{ ID: fftypes.NewUUID(), Namespace: "ns1", Name: "math", Version: "v1.0.0", - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { Name: "sum", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -50,7 +50,7 @@ func testFFI() *core.FFI { Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), }, }, - Returns: core.FFIParams{ + Returns: fftypes.FFIParams{ { Name: "result", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -58,12 +58,12 @@ func testFFI() *core.FFI { }, }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { ID: fftypes.NewUUID(), - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "event1", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "result", Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), @@ -80,7 +80,7 @@ func testContractAPI() *core.ContractAPI { ID: fftypes.NewUUID(), Namespace: "ns1", Name: "math", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.NewUUID(), }, Location: fftypes.JSONAnyPtr(""), diff --git a/internal/events/batch_pin_complete.go b/internal/events/batch_pin_complete.go index bfb391b258..c9d05b73b2 100644 --- a/internal/events/batch_pin_complete.go +++ b/internal/events/batch_pin_complete.go @@ -36,7 +36,8 @@ func (em *eventManager) BatchPinComplete(bi blockchain.Plugin, batchPin *blockch log.L(em.ctx).Errorf("Invalid BatchPin transaction - ID is nil") return nil // move on } - if err := core.ValidateFFNameField(em.ctx, batchPin.Namespace, "namespace"); err != nil { + + if err := fftypes.ValidateFFNameField(em.ctx, batchPin.Namespace, "namespace"); err != nil { log.L(em.ctx).Errorf("Invalid transaction ID='%s' - invalid namespace '%s': %a", batchPin.TransactionID, batchPin.Namespace, err) return nil // move on } diff --git a/internal/namespace/manager.go b/internal/namespace/manager.go index cd1a6db3df..14c2db86f6 100644 --- a/internal/namespace/manager.go +++ b/internal/namespace/manager.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/hyperledger/firefly-common/pkg/config" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly-common/pkg/i18n" "github.com/hyperledger/firefly-common/pkg/log" "github.com/hyperledger/firefly/internal/blockchain/bifactory" @@ -313,7 +314,7 @@ func (nm *namespaceManager) getTokensPlugins(ctx context.Context) (plugins map[s if name == "" || pluginType == "" { return nil, i18n.NewError(ctx, coremsgs.MsgMissingTokensPluginConfig) } - if err = core.ValidateFFNameField(ctx, name, "name"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, name, "name"); err != nil { return nil, err } @@ -378,7 +379,7 @@ func (nm *namespaceManager) validatePluginConfig(ctx context.Context, config con return "", "", i18n.NewError(ctx, coremsgs.MsgInvalidPluginConfiguration, sectionName) } - if err := core.ValidateFFNameField(ctx, name, "name"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, name, "name"); err != nil { return "", "", err } @@ -589,7 +590,7 @@ func (nm *namespaceManager) loadNamespaces(ctx context.Context) (err error) { } func (nm *namespaceManager) loadNamespace(ctx context.Context, name string, index int, conf config.Section) (*namespace, error) { - if err := core.ValidateFFNameField(ctx, name, fmt.Sprintf("namespaces.predefined[%d].name", index)); err != nil { + if err := fftypes.ValidateFFNameField(ctx, name, fmt.Sprintf("namespaces.predefined[%d].name", index)); err != nil { return nil, err } if name == core.LegacySystemNamespace || conf.GetString(coreconfig.NamespaceRemoteName) == core.LegacySystemNamespace { diff --git a/internal/networkmap/data_query.go b/internal/networkmap/data_query.go index 5d488155e1..ad27599005 100644 --- a/internal/networkmap/data_query.go +++ b/internal/networkmap/data_query.go @@ -31,7 +31,7 @@ import ( func (nm *networkMap) GetOrganizationByNameOrID(ctx context.Context, ns, nameOrID string) (org *core.Identity, err error) { u, err := fftypes.ParseUUID(ctx, nameOrID) if err != nil { - if err := core.ValidateFFNameField(ctx, nameOrID, "name"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, nameOrID, "name"); err != nil { return nil, err } if org, err = nm.database.GetIdentityByName(ctx, core.IdentityTypeOrg, ns, nameOrID); err != nil { @@ -63,7 +63,7 @@ func (nm *networkMap) GetOrganizationsWithVerifiers(ctx context.Context, ns stri func (nm *networkMap) GetNodeByNameOrID(ctx context.Context, ns, nameOrID string) (node *core.Identity, err error) { u, err := fftypes.ParseUUID(ctx, nameOrID) if err != nil { - if err := core.ValidateFFNameField(ctx, nameOrID, "name"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, nameOrID, "name"); err != nil { return nil, err } if node, err = nm.database.GetIdentityByName(ctx, core.IdentityTypeNode, ns, nameOrID); err != nil { diff --git a/internal/orchestrator/data_query.go b/internal/orchestrator/data_query.go index 7c7bdb5375..9898e2cde9 100644 --- a/internal/orchestrator/data_query.go +++ b/internal/orchestrator/data_query.go @@ -29,7 +29,7 @@ import ( ) func (or *orchestrator) verifyNamespaceSyntax(ctx context.Context, ns string) error { - return core.ValidateFFNameField(ctx, ns, "namespace") + return fftypes.ValidateFFNameField(ctx, ns, "namespace") } func (or *orchestrator) checkNamespace(ctx context.Context, requiredNS, objectNS string) error { @@ -158,10 +158,10 @@ func (or *orchestrator) GetDatatypeByID(ctx context.Context, ns, id string) (*co } func (or *orchestrator) GetDatatypeByName(ctx context.Context, ns, name, version string) (*core.Datatype, error) { - if err := core.ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return nil, err } - if err := core.ValidateFFNameFieldNoUUID(ctx, name, "name"); err != nil { + if err := fftypes.ValidateFFNameFieldNoUUID(ctx, name, "name"); err != nil { return nil, err } dt, err := or.database().GetDatatypeByName(ctx, ns, name, version) diff --git a/internal/orchestrator/subscriptions.go b/internal/orchestrator/subscriptions.go index fe5231e6e9..c5a02268d1 100644 --- a/internal/orchestrator/subscriptions.go +++ b/internal/orchestrator/subscriptions.go @@ -43,7 +43,7 @@ func (or *orchestrator) createUpdateSubscription(ctx context.Context, ns string, if err := or.data.VerifyNamespaceExists(ctx, subDef.Namespace); err != nil { return nil, err } - if err := core.ValidateFFNameFieldNoUUID(ctx, subDef.Name, "name"); err != nil { + if err := fftypes.ValidateFFNameFieldNoUUID(ctx, subDef.Name, "name"); err != nil { return nil, err } if subDef.Transport == system.SystemEventsTransport { diff --git a/internal/reference/reference.go b/internal/reference/reference.go index d53cc4a6a0..6bb44a02d2 100644 --- a/internal/reference/reference.go +++ b/internal/reference/reference.go @@ -92,7 +92,7 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e ID: fftypes.MustParseUUID("0f12317b-85a0-4a77-a722-857ea2b0a5fa"), Name: "my_contract_api", Namespace: "ns1", - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.MustParseUUID("c35d3449-4f24-4676-8e64-91c9e46f06c4"), }, Location: fftypes.JSONAnyPtr(`{ @@ -157,14 +157,14 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e Created: fftypes.UnixTime(1652664195), }, - &core.FFI{ + &fftypes.FFI{ ID: fftypes.MustParseUUID("c35d3449-4f24-4676-8e64-91c9e46f06c4"), Namespace: "ns1", Name: "SimpleStorage", Description: "A simple example contract in Solidity", Version: "v0.0.1", Message: fftypes.MustParseUUID("e4ad2077-5714-416e-81f9-7964a6223b6f"), - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ { ID: fftypes.MustParseUUID("8f3289dd-3a19-4a9f-aab3-cb05289b013c"), Interface: fftypes.MustParseUUID("c35d3449-4f24-4676-8e64-91c9e46f06c4"), @@ -172,8 +172,8 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e Namespace: "ns1", Pathname: "get", Description: "Get the current value", - Params: core.FFIParams{}, - Returns: core.FFIParams{ + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{ { Name: "output", Schema: fftypes.JSONAnyPtr(`{ @@ -195,7 +195,7 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e Namespace: "ns1", Pathname: "set", Description: "Set the value", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "newValue", Schema: fftypes.JSONAnyPtr(`{ @@ -206,23 +206,23 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e }`), }, }, - Returns: core.FFIParams{}, + Returns: fftypes.FFIParams{}, Details: fftypes.JSONObject{ "stateMutability": "payable", }, }, }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ { ID: fftypes.MustParseUUID("9f653f93-86f4-45bc-be75-d7f5888fbbc0"), Interface: fftypes.MustParseUUID("c35d3449-4f24-4676-8e64-91c9e46f06c4"), Namespace: "ns1", Pathname: "Changed", Signature: "Changed(address,uint256)", - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "Changed", Description: "Emitted when the value changes", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "_from", Schema: fftypes.JSONAnyPtr(`{ @@ -251,7 +251,7 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e &core.ContractListener{ ID: fftypes.MustParseUUID("d61980a9-748c-4c72-baf5-8b485b514d59"), - Interface: &core.FFIReference{ + Interface: &fftypes.FFIReference{ ID: fftypes.MustParseUUID("ff1da3c1-f9e7-40c2-8d93-abb8855e8a1d"), }, Namespace: "ns1", @@ -262,9 +262,9 @@ func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, e }`), Created: fftypes.UnixTime(1652664195), Event: &core.FFISerializedEvent{ - FFIEventDefinition: core.FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "Changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "x", Schema: fftypes.JSONAnyPtr(`{ diff --git a/internal/txcommon/event_enrich_test.go b/internal/txcommon/event_enrich_test.go index 1852cc2881..d139955012 100644 --- a/internal/txcommon/event_enrich_test.go +++ b/internal/txcommon/event_enrich_test.go @@ -262,7 +262,7 @@ func TestEnrichContractInterfaceSubmitted(t *testing.T) { ev1 := fftypes.NewUUID() // Setup enrichment - mdi.On("GetFFIByID", mock.Anything, ref1).Return(&core.FFI{ + mdi.On("GetFFIByID", mock.Anything, ref1).Return(&fftypes.FFI{ ID: ref1, }, nil) diff --git a/mocks/apiservermocks/ffi_swagger_gen.go b/mocks/apiservermocks/ffi_swagger_gen.go index b2627ad062..ef5859a0b7 100644 --- a/mocks/apiservermocks/ffi_swagger_gen.go +++ b/mocks/apiservermocks/ffi_swagger_gen.go @@ -5,7 +5,9 @@ package apiservermocks import ( context "context" + fftypes "github.com/hyperledger/firefly-common/pkg/fftypes" core "github.com/hyperledger/firefly/pkg/core" + mock "github.com/stretchr/testify/mock" openapi3 "github.com/getkin/kin-openapi/openapi3" @@ -17,11 +19,11 @@ type FFISwaggerGen struct { } // Generate provides a mock function with given fields: ctx, baseURL, api, ffi -func (_m *FFISwaggerGen) Generate(ctx context.Context, baseURL string, api *core.ContractAPI, ffi *core.FFI) *openapi3.T { +func (_m *FFISwaggerGen) Generate(ctx context.Context, baseURL string, api *core.ContractAPI, ffi *fftypes.FFI) *openapi3.T { ret := _m.Called(ctx, baseURL, api, ffi) var r0 *openapi3.T - if rf, ok := ret.Get(0).(func(context.Context, string, *core.ContractAPI, *core.FFI) *openapi3.T); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, *core.ContractAPI, *fftypes.FFI) *openapi3.T); ok { r0 = rf(ctx, baseURL, api, ffi) } else { if ret.Get(0) != nil { diff --git a/mocks/blockchainmocks/plugin.go b/mocks/blockchainmocks/plugin.go index 11eeebac0f..60d93e835f 100644 --- a/mocks/blockchainmocks/plugin.go +++ b/mocks/blockchainmocks/plugin.go @@ -81,11 +81,11 @@ func (_m *Plugin) DeleteContractListener(ctx context.Context, subscription *core } // GenerateEventSignature provides a mock function with given fields: ctx, event -func (_m *Plugin) GenerateEventSignature(ctx context.Context, event *core.FFIEventDefinition) string { +func (_m *Plugin) GenerateEventSignature(ctx context.Context, event *fftypes.FFIEventDefinition) string { ret := _m.Called(ctx, event) var r0 string - if rf, ok := ret.Get(0).(func(context.Context, *core.FFIEventDefinition) string); ok { + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.FFIEventDefinition) string); ok { r0 = rf(ctx, event) } else { r0 = ret.Get(0).(string) @@ -95,20 +95,20 @@ func (_m *Plugin) GenerateEventSignature(ctx context.Context, event *core.FFIEve } // GenerateFFI provides a mock function with given fields: ctx, generationRequest -func (_m *Plugin) GenerateFFI(ctx context.Context, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) { +func (_m *Plugin) GenerateFFI(ctx context.Context, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) { ret := _m.Called(ctx, generationRequest) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, *core.FFIGenerationRequest) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.FFIGenerationRequest) *fftypes.FFI); ok { r0 = rf(ctx, generationRequest) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *core.FFIGenerationRequest) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *fftypes.FFIGenerationRequest) error); ok { r1 = rf(ctx, generationRequest) } else { r1 = ret.Error(1) @@ -118,15 +118,15 @@ func (_m *Plugin) GenerateFFI(ctx context.Context, generationRequest *core.FFIGe } // GetFFIParamValidator provides a mock function with given fields: ctx -func (_m *Plugin) GetFFIParamValidator(ctx context.Context) (core.FFIParamValidator, error) { +func (_m *Plugin) GetFFIParamValidator(ctx context.Context) (fftypes.FFIParamValidator, error) { ret := _m.Called(ctx) - var r0 core.FFIParamValidator - if rf, ok := ret.Get(0).(func(context.Context) core.FFIParamValidator); ok { + var r0 fftypes.FFIParamValidator + if rf, ok := ret.Get(0).(func(context.Context) fftypes.FFIParamValidator); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(core.FFIParamValidator) + r0 = ret.Get(0).(fftypes.FFIParamValidator) } } @@ -160,11 +160,11 @@ func (_m *Plugin) InitConfig(_a0 config.Section) { } // InvokeContract provides a mock function with given fields: ctx, nsOpID, signingKey, location, method, input, options -func (_m *Plugin) InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) error { +func (_m *Plugin) InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) error { ret := _m.Called(ctx, nsOpID, signingKey, location, method, input, options) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, *fftypes.JSONAny, *core.FFIMethod, map[string]interface{}, map[string]interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, string, *fftypes.JSONAny, *fftypes.FFIMethod, map[string]interface{}, map[string]interface{}) error); ok { r0 = rf(ctx, nsOpID, signingKey, location, method, input, options) } else { r0 = ret.Error(0) @@ -246,11 +246,11 @@ func (_m *Plugin) NormalizeSigningKey(ctx context.Context, keyRef string) (strin } // QueryContract provides a mock function with given fields: ctx, location, method, input, options -func (_m *Plugin) QueryContract(ctx context.Context, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) { +func (_m *Plugin) QueryContract(ctx context.Context, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) { ret := _m.Called(ctx, location, method, input, options) var r0 interface{} - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.JSONAny, *core.FFIMethod, map[string]interface{}, map[string]interface{}) interface{}); ok { + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.JSONAny, *fftypes.FFIMethod, map[string]interface{}, map[string]interface{}) interface{}); ok { r0 = rf(ctx, location, method, input, options) } else { if ret.Get(0) != nil { @@ -259,7 +259,7 @@ func (_m *Plugin) QueryContract(ctx context.Context, location *fftypes.JSONAny, } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *fftypes.JSONAny, *core.FFIMethod, map[string]interface{}, map[string]interface{}) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *fftypes.JSONAny, *fftypes.FFIMethod, map[string]interface{}, map[string]interface{}) error); ok { r1 = rf(ctx, location, method, input, options) } else { r1 = ret.Error(1) diff --git a/mocks/contractmocks/manager.go b/mocks/contractmocks/manager.go index 1a09709c12..45de711698 100644 --- a/mocks/contractmocks/manager.go +++ b/mocks/contractmocks/manager.go @@ -89,20 +89,20 @@ func (_m *Manager) BroadcastContractAPI(ctx context.Context, httpServerURL strin } // BroadcastFFI provides a mock function with given fields: ctx, ns, ffi, waitConfirm -func (_m *Manager) BroadcastFFI(ctx context.Context, ns string, ffi *core.FFI, waitConfirm bool) (*core.FFI, error) { +func (_m *Manager) BroadcastFFI(ctx context.Context, ns string, ffi *fftypes.FFI, waitConfirm bool) (*fftypes.FFI, error) { ret := _m.Called(ctx, ns, ffi, waitConfirm) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, *core.FFI, bool) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.FFI, bool) *fftypes.FFI); ok { r0 = rf(ctx, ns, ffi, waitConfirm) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.FFI, bool) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, *fftypes.FFI, bool) error); ok { r1 = rf(ctx, ns, ffi, waitConfirm) } else { r1 = ret.Error(1) @@ -126,20 +126,20 @@ func (_m *Manager) DeleteContractListenerByNameOrID(ctx context.Context, ns stri } // GenerateFFI provides a mock function with given fields: ctx, ns, generationRequest -func (_m *Manager) GenerateFFI(ctx context.Context, ns string, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) { +func (_m *Manager) GenerateFFI(ctx context.Context, ns string, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) { ret := _m.Called(ctx, ns, generationRequest) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, *core.FFIGenerationRequest) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.FFIGenerationRequest) *fftypes.FFI); ok { r0 = rf(ctx, ns, generationRequest) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, string, *core.FFIGenerationRequest) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, *fftypes.FFIGenerationRequest) error); ok { r1 = rf(ctx, ns, generationRequest) } else { r1 = ret.Error(1) @@ -172,15 +172,15 @@ func (_m *Manager) GetContractAPI(ctx context.Context, httpServerURL string, ns } // GetContractAPIInterface provides a mock function with given fields: ctx, ns, apiName -func (_m *Manager) GetContractAPIInterface(ctx context.Context, ns string, apiName string) (*core.FFI, error) { +func (_m *Manager) GetContractAPIInterface(ctx context.Context, ns string, apiName string) (*fftypes.FFI, error) { ret := _m.Called(ctx, ns, apiName) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, string) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, string) *fftypes.FFI); ok { r0 = rf(ctx, ns, apiName) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -314,15 +314,15 @@ func (_m *Manager) GetContractListeners(ctx context.Context, ns string, filter d } // GetFFI provides a mock function with given fields: ctx, ns, name, version -func (_m *Manager) GetFFI(ctx context.Context, ns string, name string, version string) (*core.FFI, error) { +func (_m *Manager) GetFFI(ctx context.Context, ns string, name string, version string) (*fftypes.FFI, error) { ret := _m.Called(ctx, ns, name, version) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *fftypes.FFI); ok { r0 = rf(ctx, ns, name, version) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -337,15 +337,15 @@ func (_m *Manager) GetFFI(ctx context.Context, ns string, name string, version s } // GetFFIByID provides a mock function with given fields: ctx, id -func (_m *Manager) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) { +func (_m *Manager) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) { ret := _m.Called(ctx, id) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *fftypes.FFI); ok { r0 = rf(ctx, id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -360,15 +360,15 @@ func (_m *Manager) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, } // GetFFIByIDWithChildren provides a mock function with given fields: ctx, id -func (_m *Manager) GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) { +func (_m *Manager) GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) { ret := _m.Called(ctx, id) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *fftypes.FFI); ok { r0 = rf(ctx, id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -383,15 +383,15 @@ func (_m *Manager) GetFFIByIDWithChildren(ctx context.Context, id *fftypes.UUID) } // GetFFIWithChildren provides a mock function with given fields: ctx, ns, name, version -func (_m *Manager) GetFFIWithChildren(ctx context.Context, ns string, name string, version string) (*core.FFI, error) { +func (_m *Manager) GetFFIWithChildren(ctx context.Context, ns string, name string, version string) (*fftypes.FFI, error) { ret := _m.Called(ctx, ns, name, version) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *fftypes.FFI); ok { r0 = rf(ctx, ns, name, version) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -406,15 +406,15 @@ func (_m *Manager) GetFFIWithChildren(ctx context.Context, ns string, name strin } // GetFFIs provides a mock function with given fields: ctx, ns, filter -func (_m *Manager) GetFFIs(ctx context.Context, ns string, filter database.AndFilter) ([]*core.FFI, *database.FilterResult, error) { +func (_m *Manager) GetFFIs(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.FFI, *database.FilterResult, error) { ret := _m.Called(ctx, ns, filter) - var r0 []*core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, database.AndFilter) []*core.FFI); ok { + var r0 []*fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, database.AndFilter) []*fftypes.FFI); ok { r0 = rf(ctx, ns, filter) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*core.FFI) + r0 = ret.Get(0).([]*fftypes.FFI) } } @@ -551,11 +551,11 @@ func (_m *Manager) RunOperation(ctx context.Context, op *core.PreparedOperation) } // ValidateFFIAndSetPathnames provides a mock function with given fields: ctx, ffi -func (_m *Manager) ValidateFFIAndSetPathnames(ctx context.Context, ffi *core.FFI) error { +func (_m *Manager) ValidateFFIAndSetPathnames(ctx context.Context, ffi *fftypes.FFI) error { ret := _m.Called(ctx, ffi) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *core.FFI) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.FFI) error); ok { r0 = rf(ctx, ffi) } else { r0 = ret.Error(0) diff --git a/mocks/databasemocks/plugin.go b/mocks/databasemocks/plugin.go index 37e33d2399..f8ce291425 100644 --- a/mocks/databasemocks/plugin.go +++ b/mocks/databasemocks/plugin.go @@ -861,15 +861,15 @@ func (_m *Plugin) GetEvents(ctx context.Context, filter database.Filter) ([]*cor } // GetFFI provides a mock function with given fields: ctx, ns, name, version -func (_m *Plugin) GetFFI(ctx context.Context, ns string, name string, version string) (*core.FFI, error) { +func (_m *Plugin) GetFFI(ctx context.Context, ns string, name string, version string) (*fftypes.FFI, error) { ret := _m.Called(ctx, ns, name, version) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *fftypes.FFI); ok { r0 = rf(ctx, ns, name, version) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -884,15 +884,15 @@ func (_m *Plugin) GetFFI(ctx context.Context, ns string, name string, version st } // GetFFIByID provides a mock function with given fields: ctx, id -func (_m *Plugin) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) { +func (_m *Plugin) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) { ret := _m.Called(ctx, id) - var r0 *core.FFI - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *core.FFI); ok { + var r0 *fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *fftypes.FFI); ok { r0 = rf(ctx, id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFI) + r0 = ret.Get(0).(*fftypes.FFI) } } @@ -907,15 +907,15 @@ func (_m *Plugin) GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, } // GetFFIEvent provides a mock function with given fields: ctx, ns, interfaceID, pathName -func (_m *Plugin) GetFFIEvent(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*core.FFIEvent, error) { +func (_m *Plugin) GetFFIEvent(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*fftypes.FFIEvent, error) { ret := _m.Called(ctx, ns, interfaceID, pathName) - var r0 *core.FFIEvent - if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, string) *core.FFIEvent); ok { + var r0 *fftypes.FFIEvent + if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, string) *fftypes.FFIEvent); ok { r0 = rf(ctx, ns, interfaceID, pathName) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFIEvent) + r0 = ret.Get(0).(*fftypes.FFIEvent) } } @@ -930,15 +930,15 @@ func (_m *Plugin) GetFFIEvent(ctx context.Context, ns string, interfaceID *fftyp } // GetFFIEventByID provides a mock function with given fields: ctx, id -func (_m *Plugin) GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*core.FFIEvent, error) { +func (_m *Plugin) GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFIEvent, error) { ret := _m.Called(ctx, id) - var r0 *core.FFIEvent - if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *core.FFIEvent); ok { + var r0 *fftypes.FFIEvent + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.UUID) *fftypes.FFIEvent); ok { r0 = rf(ctx, id) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFIEvent) + r0 = ret.Get(0).(*fftypes.FFIEvent) } } @@ -953,15 +953,15 @@ func (_m *Plugin) GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*core. } // GetFFIEvents provides a mock function with given fields: ctx, filter -func (_m *Plugin) GetFFIEvents(ctx context.Context, filter database.Filter) ([]*core.FFIEvent, *database.FilterResult, error) { +func (_m *Plugin) GetFFIEvents(ctx context.Context, filter database.Filter) ([]*fftypes.FFIEvent, *database.FilterResult, error) { ret := _m.Called(ctx, filter) - var r0 []*core.FFIEvent - if rf, ok := ret.Get(0).(func(context.Context, database.Filter) []*core.FFIEvent); ok { + var r0 []*fftypes.FFIEvent + if rf, ok := ret.Get(0).(func(context.Context, database.Filter) []*fftypes.FFIEvent); ok { r0 = rf(ctx, filter) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*core.FFIEvent) + r0 = ret.Get(0).([]*fftypes.FFIEvent) } } @@ -985,15 +985,15 @@ func (_m *Plugin) GetFFIEvents(ctx context.Context, filter database.Filter) ([]* } // GetFFIMethod provides a mock function with given fields: ctx, ns, interfaceID, pathName -func (_m *Plugin) GetFFIMethod(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*core.FFIMethod, error) { +func (_m *Plugin) GetFFIMethod(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*fftypes.FFIMethod, error) { ret := _m.Called(ctx, ns, interfaceID, pathName) - var r0 *core.FFIMethod - if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, string) *core.FFIMethod); ok { + var r0 *fftypes.FFIMethod + if rf, ok := ret.Get(0).(func(context.Context, string, *fftypes.UUID, string) *fftypes.FFIMethod); ok { r0 = rf(ctx, ns, interfaceID, pathName) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*core.FFIMethod) + r0 = ret.Get(0).(*fftypes.FFIMethod) } } @@ -1008,15 +1008,15 @@ func (_m *Plugin) GetFFIMethod(ctx context.Context, ns string, interfaceID *ffty } // GetFFIMethods provides a mock function with given fields: ctx, filter -func (_m *Plugin) GetFFIMethods(ctx context.Context, filter database.Filter) ([]*core.FFIMethod, *database.FilterResult, error) { +func (_m *Plugin) GetFFIMethods(ctx context.Context, filter database.Filter) ([]*fftypes.FFIMethod, *database.FilterResult, error) { ret := _m.Called(ctx, filter) - var r0 []*core.FFIMethod - if rf, ok := ret.Get(0).(func(context.Context, database.Filter) []*core.FFIMethod); ok { + var r0 []*fftypes.FFIMethod + if rf, ok := ret.Get(0).(func(context.Context, database.Filter) []*fftypes.FFIMethod); ok { r0 = rf(ctx, filter) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*core.FFIMethod) + r0 = ret.Get(0).([]*fftypes.FFIMethod) } } @@ -1040,15 +1040,15 @@ func (_m *Plugin) GetFFIMethods(ctx context.Context, filter database.Filter) ([] } // GetFFIs provides a mock function with given fields: ctx, ns, filter -func (_m *Plugin) GetFFIs(ctx context.Context, ns string, filter database.Filter) ([]*core.FFI, *database.FilterResult, error) { +func (_m *Plugin) GetFFIs(ctx context.Context, ns string, filter database.Filter) ([]*fftypes.FFI, *database.FilterResult, error) { ret := _m.Called(ctx, ns, filter) - var r0 []*core.FFI - if rf, ok := ret.Get(0).(func(context.Context, string, database.Filter) []*core.FFI); ok { + var r0 []*fftypes.FFI + if rf, ok := ret.Get(0).(func(context.Context, string, database.Filter) []*fftypes.FFI); ok { r0 = rf(ctx, ns, filter) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*core.FFI) + r0 = ret.Get(0).([]*fftypes.FFI) } } @@ -2830,11 +2830,11 @@ func (_m *Plugin) UpsertDatatype(ctx context.Context, datadef *core.Datatype, al } // UpsertFFI provides a mock function with given fields: ctx, cd -func (_m *Plugin) UpsertFFI(ctx context.Context, cd *core.FFI) error { +func (_m *Plugin) UpsertFFI(ctx context.Context, cd *fftypes.FFI) error { ret := _m.Called(ctx, cd) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *core.FFI) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.FFI) error); ok { r0 = rf(ctx, cd) } else { r0 = ret.Error(0) @@ -2844,11 +2844,11 @@ func (_m *Plugin) UpsertFFI(ctx context.Context, cd *core.FFI) error { } // UpsertFFIEvent provides a mock function with given fields: ctx, method -func (_m *Plugin) UpsertFFIEvent(ctx context.Context, method *core.FFIEvent) error { +func (_m *Plugin) UpsertFFIEvent(ctx context.Context, method *fftypes.FFIEvent) error { ret := _m.Called(ctx, method) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *core.FFIEvent) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.FFIEvent) error); ok { r0 = rf(ctx, method) } else { r0 = ret.Error(0) @@ -2858,11 +2858,11 @@ func (_m *Plugin) UpsertFFIEvent(ctx context.Context, method *core.FFIEvent) err } // UpsertFFIMethod provides a mock function with given fields: ctx, method -func (_m *Plugin) UpsertFFIMethod(ctx context.Context, method *core.FFIMethod) error { +func (_m *Plugin) UpsertFFIMethod(ctx context.Context, method *fftypes.FFIMethod) error { ret := _m.Called(ctx, method) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *core.FFIMethod) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *fftypes.FFIMethod) error); ok { r0 = rf(ctx, method) } else { r0 = ret.Error(0) diff --git a/pkg/blockchain/plugin.go b/pkg/blockchain/plugin.go index 4ae497d9bb..d82fb82ff0 100644 --- a/pkg/blockchain/plugin.go +++ b/pkg/blockchain/plugin.go @@ -70,10 +70,10 @@ type Plugin interface { SubmitNetworkAction(ctx context.Context, nsOpID string, signingKey string, action core.NetworkActionType) error // InvokeContract submits a new transaction to be executed by custom on-chain logic - InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) error + InvokeContract(ctx context.Context, nsOpID string, signingKey string, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) error // QueryContract executes a method via custom on-chain logic and returns the result - QueryContract(ctx context.Context, location *fftypes.JSONAny, method *core.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) + QueryContract(ctx context.Context, location *fftypes.JSONAny, method *fftypes.FFIMethod, input map[string]interface{}, options map[string]interface{}) (interface{}, error) // AddContractListener adds a new subscription to a user-specified contract and event AddContractListener(ctx context.Context, subscription *core.ContractListenerInput) error @@ -82,16 +82,16 @@ type Plugin interface { DeleteContractListener(ctx context.Context, subscription *core.ContractListener) error // GetFFIParamValidator returns a blockchain-plugin-specific validator for FFIParams and their JSON Schema - GetFFIParamValidator(ctx context.Context) (core.FFIParamValidator, error) + GetFFIParamValidator(ctx context.Context) (fftypes.FFIParamValidator, error) // GenerateFFI returns an FFI from a blockchain specific interface format e.g. an Ethereum ABI - GenerateFFI(ctx context.Context, generationRequest *core.FFIGenerationRequest) (*core.FFI, error) + GenerateFFI(ctx context.Context, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) // NormalizeContractLocation validates and normalizes the formatting of the location JSON NormalizeContractLocation(ctx context.Context, location *fftypes.JSONAny) (*fftypes.JSONAny, error) // GenerateEventSignature generates a strigified signature for the event, incorporating any fields significant to identifying the event as unique - GenerateEventSignature(ctx context.Context, event *core.FFIEventDefinition) string + GenerateEventSignature(ctx context.Context, event *fftypes.FFIEventDefinition) string // NetworkVersion returns the version of the network rules being used by this plugin NetworkVersion() int diff --git a/pkg/core/contract_listener.go b/pkg/core/contract_listener.go index 2b9a3d3b4d..d68e65b258 100644 --- a/pkg/core/contract_listener.go +++ b/pkg/core/contract_listener.go @@ -27,7 +27,7 @@ import ( type ContractListener struct { ID *fftypes.UUID `ffstruct:"ContractListener" json:"id,omitempty" ffexcludeinput:"true"` - Interface *FFIReference `ffstruct:"ContractListener" json:"interface,omitempty" ffexcludeinput:"postContractAPIListeners"` + Interface *fftypes.FFIReference `ffstruct:"ContractListener" json:"interface,omitempty" ffexcludeinput:"postContractAPIListeners"` Namespace string `ffstruct:"ContractListener" json:"namespace,omitempty" ffexcludeinput:"true"` Name string `ffstruct:"ContractListener" json:"name,omitempty"` BackendID string `ffstruct:"ContractListener" json:"backendId,omitempty" ffexcludeinput:"true"` @@ -49,7 +49,7 @@ type ContractListenerInput struct { } type FFISerializedEvent struct { - FFIEventDefinition + fftypes.FFIEventDefinition } // Scan implements sql.Scanner diff --git a/pkg/core/contract_listener_test.go b/pkg/core/contract_listener_test.go index d086644b91..fbbaf88ca7 100644 --- a/pkg/core/contract_listener_test.go +++ b/pkg/core/contract_listener_test.go @@ -49,11 +49,11 @@ func TestFFISerializedEventScanError(t *testing.T) { func TestFFISerializedEventValue(t *testing.T) { params := &FFISerializedEvent{ - FFIEventDefinition: FFIEventDefinition{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "event1", Description: "a super event", - Params: FFIParams{ - &FFIParam{Name: "details", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`)}, + Params: fftypes.FFIParams{ + &fftypes.FFIParam{Name: "details", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`)}, }, }, } diff --git a/pkg/core/contracts.go b/pkg/core/contracts.go index 7dc69484b2..69a6289c9c 100644 --- a/pkg/core/contracts.go +++ b/pkg/core/contracts.go @@ -36,7 +36,7 @@ type ContractCallRequest struct { Interface *fftypes.UUID `ffstruct:"ContractCallRequest" json:"interface,omitempty" ffexcludeinput:"postContractAPIInvoke,postContractAPIQuery"` Location *fftypes.JSONAny `ffstruct:"ContractCallRequest" json:"location,omitempty"` Key string `ffstruct:"ContractCallRequest" json:"key,omitempty"` - Method *FFIMethod `ffstruct:"ContractCallRequest" json:"method,omitempty" ffexcludeinput:"postContractAPIInvoke,postContractAPIQuery"` + Method *fftypes.FFIMethod `ffstruct:"ContractCallRequest" json:"method,omitempty" ffexcludeinput:"postContractAPIInvoke,postContractAPIQuery"` MethodPath string `ffstruct:"ContractCallRequest" json:"methodPath,omitempty" ffexcludeinput:"postContractAPIInvoke,postContractAPIQuery"` Input map[string]interface{} `ffstruct:"ContractCallRequest" json:"input"` Options map[string]interface{} `ffstruct:"ContractCallRequest" json:"options"` @@ -48,27 +48,27 @@ type ContractURLs struct { } type ContractAPI struct { - ID *fftypes.UUID `ffstruct:"ContractAPI" json:"id,omitempty" ffexcludeinput:"true"` - Namespace string `ffstruct:"ContractAPI" json:"namespace,omitempty" ffexcludeinput:"true"` - Interface *FFIReference `ffstruct:"ContractAPI" json:"interface"` - Location *fftypes.JSONAny `ffstruct:"ContractAPI" json:"location,omitempty"` - Name string `ffstruct:"ContractAPI" json:"name"` - Message *fftypes.UUID `ffstruct:"ContractAPI" json:"message,omitempty" ffexcludeinput:"true"` - URLs ContractURLs `ffstruct:"ContractAPI" json:"urls" ffexcludeinput:"true"` + ID *fftypes.UUID `ffstruct:"ContractAPI" json:"id,omitempty" ffexcludeinput:"true"` + Namespace string `ffstruct:"ContractAPI" json:"namespace,omitempty" ffexcludeinput:"true"` + Interface *fftypes.FFIReference `ffstruct:"ContractAPI" json:"interface"` + Location *fftypes.JSONAny `ffstruct:"ContractAPI" json:"location,omitempty"` + Name string `ffstruct:"ContractAPI" json:"name"` + Message *fftypes.UUID `ffstruct:"ContractAPI" json:"message,omitempty" ffexcludeinput:"true"` + URLs ContractURLs `ffstruct:"ContractAPI" json:"urls" ffexcludeinput:"true"` } func (c *ContractAPI) Validate(ctx context.Context, existing bool) (err error) { - if err = ValidateFFNameField(ctx, c.Namespace, "namespace"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, c.Namespace, "namespace"); err != nil { return err } - if err = ValidateFFNameField(ctx, c.Name, "name"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, c.Name, "name"); err != nil { return err } return nil } func (c *ContractAPI) Topic() string { - return typeNamespaceNameTopicHash("contractapi", c.Namespace, c.Name) + return fftypes.TypeNamespaceNameTopicHash("contractapi", c.Namespace, c.Name) } func (c *ContractAPI) SetBroadcastMessage(msgID *fftypes.UUID) { diff --git a/pkg/core/datatype.go b/pkg/core/datatype.go index 1253d6803c..a66e86973e 100644 --- a/pkg/core/datatype.go +++ b/pkg/core/datatype.go @@ -51,13 +51,13 @@ func (dt *Datatype) Validate(ctx context.Context, existing bool) (err error) { if dt.Validator != ValidatorTypeJSON { return i18n.NewError(ctx, i18n.MsgUnknownFieldValue, "validator", dt.Validator) } - if err = ValidateFFNameField(ctx, dt.Namespace, "namespace"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, dt.Namespace, "namespace"); err != nil { return err } - if err = ValidateFFNameFieldNoUUID(ctx, dt.Name, "name"); err != nil { + if err = fftypes.ValidateFFNameFieldNoUUID(ctx, dt.Name, "name"); err != nil { return err } - if err = ValidateFFNameField(ctx, dt.Version, "version"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, dt.Version, "version"); err != nil { return err } if dt.Value == nil || len(*dt.Value) == 0 { @@ -76,7 +76,7 @@ func (dt *Datatype) Validate(ctx context.Context, existing bool) (err error) { } func (dt *Datatype) Topic() string { - return typeNamespaceNameTopicHash("datatype", dt.Namespace, dt.Name) + return fftypes.TypeNamespaceNameTopicHash("datatype", dt.Namespace, dt.Name) } func (dt *Datatype) SetBroadcastMessage(msgID *fftypes.UUID) { diff --git a/pkg/core/event.go b/pkg/core/event.go index afeb43ea4a..170b8644fc 100644 --- a/pkg/core/event.go +++ b/pkg/core/event.go @@ -79,7 +79,7 @@ type EnrichedEvent struct { Event BlockchainEvent *BlockchainEvent `ffstruct:"EnrichedEvent" json:"blockchainEvent,omitempty"` ContractAPI *ContractAPI `ffstruct:"EnrichedEvent" json:"contractAPI,omitempty"` - ContractInterface *FFI `ffstruct:"EnrichedEvent" json:"contractInterface,omitempty"` + ContractInterface *fftypes.FFI `ffstruct:"EnrichedEvent" json:"contractInterface,omitempty"` Datatype *Datatype `ffstruct:"EnrichedEvent" json:"datatype,omitempty"` Identity *Identity `ffstruct:"EnrichedEvent" json:"identity,omitempty"` Message *Message `ffstruct:"EnrichedEvent" json:"message,omitempty"` diff --git a/pkg/core/ffi.go b/pkg/core/ffi.go deleted file mode 100644 index 504cacf802..0000000000 --- a/pkg/core/ffi.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core - -import ( - "context" - "database/sql/driver" - "encoding/json" - - "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/hyperledger/firefly-common/pkg/i18n" - "github.com/santhosh-tekuri/jsonschema/v5" -) - -// FFIInputType is the type of a JSON field in a request to FireFly's API -type FFIInputType = fftypes.FFEnum - -var ( - // FFIInputTypeInteger is a json integer or string to be treated as an integer - FFIInputTypeInteger = fftypes.FFEnumValue("ffiinputtype", "integer") - // FFIInputTypeString is a JSON string - FFIInputTypeString = fftypes.FFEnumValue("ffiinputtype", "string") - // FFIInputTypeArray is a JSON boolean - FFIInputTypeBoolean = fftypes.FFEnumValue("ffiinputtype", "boolean") - // FFIInputTypeArray is a JSON array - FFIInputTypeArray = fftypes.FFEnumValue("ffiinputtype", "array") - // FFIInputTypeObject is a JSON object - FFIInputTypeObject = fftypes.FFEnumValue("ffiinputtype", "object") -) - -type FFIParamValidator interface { - Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error) - GetMetaSchema() *jsonschema.Schema - GetExtensionName() string -} - -type FFIReference struct { - ID *fftypes.UUID `ffstruct:"FFIReference" json:"id,omitempty"` - Name string `ffstruct:"FFIReference" json:"name,omitempty"` - Version string `ffstruct:"FFIReference" json:"version,omitempty"` -} - -type FFI struct { - ID *fftypes.UUID `ffstruct:"FFI" json:"id,omitempty" ffexcludeinput:"true"` - Message *fftypes.UUID `ffstruct:"FFI" json:"message,omitempty" ffexcludeinput:"true"` - Namespace string `ffstruct:"FFI" json:"namespace,omitempty" ffexcludeinput:"true"` - Name string `ffstruct:"FFI" json:"name"` - Description string `ffstruct:"FFI" json:"description"` - Version string `ffstruct:"FFI" json:"version"` - Methods []*FFIMethod `ffstruct:"FFI" json:"methods,omitempty"` - Events []*FFIEvent `ffstruct:"FFI" json:"events,omitempty"` -} - -type FFIMethod struct { - ID *fftypes.UUID `ffstruct:"FFIMethod" json:"id,omitempty" ffexcludeinput:"true"` - Interface *fftypes.UUID `ffstruct:"FFIMethod" json:"interface,omitempty" ffexcludeinput:"true"` - Name string `ffstruct:"FFIMethod" json:"name"` - Namespace string `ffstruct:"FFIMethod" json:"namespace,omitempty" ffexcludeinput:"true"` - Pathname string `ffstruct:"FFIMethod" json:"pathname" ffexcludeinput:"true"` - Description string `ffstruct:"FFIMethod" json:"description"` - Params FFIParams `ffstruct:"FFIMethod" json:"params"` - Returns FFIParams `ffstruct:"FFIMethod" json:"returns"` - Details fftypes.JSONObject `ffstruct:"FFIMethod" json:"details,omitempty"` -} - -type FFIEventDefinition struct { - Name string `ffstruct:"FFIEvent" json:"name"` - Description string `ffstruct:"FFIEvent" json:"description"` - Params FFIParams `ffstruct:"FFIEvent" json:"params"` - Details fftypes.JSONObject `ffstruct:"FFIEvent" json:"details,omitempty"` -} - -type FFIEvent struct { - ID *fftypes.UUID `ffstruct:"FFIEvent" json:"id,omitempty" ffexcludeinput:"true"` - Interface *fftypes.UUID `ffstruct:"FFIEvent" json:"interface,omitempty" ffexcludeinput:"true"` - Namespace string `ffstruct:"FFIEvent" json:"namespace,omitempty" ffexcludeinput:"true"` - Pathname string `ffstruct:"FFIEvent" json:"pathname,omitempty" ffexcludeinput:"true"` - Signature string `ffstruct:"FFIEvent" json:"signature" ffexcludeinput:"true"` - FFIEventDefinition -} - -type FFIParam struct { - Name string `ffstruct:"FFIParam" json:"name"` - Schema *fftypes.JSONAny `ffstruct:"FFIParam" json:"schema,omitempty"` -} - -type FFIParams []*FFIParam - -type FFIGenerationRequest struct { - Namespace string `ffstruct:"FFIGenerationRequest" json:"namespace,omitempty"` - Name string `ffstruct:"FFIGenerationRequest" json:"name"` - Description string `ffstruct:"FFIGenerationRequest" json:"description"` - Version string `ffstruct:"FFIGenerationRequest" json:"version"` - Input *fftypes.JSONAny `ffstruct:"FFIGenerationRequest" json:"input"` -} - -func (f *FFI) Validate(ctx context.Context, existing bool) (err error) { - if err = ValidateFFNameField(ctx, f.Namespace, "namespace"); err != nil { - return err - } - if err = ValidateFFNameField(ctx, f.Name, "name"); err != nil { - return err - } - if err = ValidateFFNameField(ctx, f.Version, "version"); err != nil { - return err - } - return nil -} - -func (f *FFI) Topic() string { - return typeNamespaceNameTopicHash("ffi", f.Namespace, f.Name) -} - -func (f *FFI) SetBroadcastMessage(msgID *fftypes.UUID) { - f.Message = msgID -} - -// Scan implements sql.Scanner -func (p *FFIParams) Scan(src interface{}) error { - switch src := src.(type) { - case nil: - p = nil - return nil - case string: - return json.Unmarshal([]byte(src), &p) - case []byte: - return json.Unmarshal(src, &p) - default: - return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, p) - } -} - -func (p FFIParams) Value() (driver.Value, error) { - bytes, _ := json.Marshal(p) - return bytes, nil -} diff --git a/pkg/core/ffi_param_validator.go b/pkg/core/ffi_param_validator.go deleted file mode 100644 index 2ac9256863..0000000000 --- a/pkg/core/ffi_param_validator.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core - -import ( - "github.com/santhosh-tekuri/jsonschema/v5" -) - -type BaseFFIParamValidator struct{} - -func (v BaseFFIParamValidator) Compile(ctx jsonschema.CompilerContext, m map[string]interface{}) (jsonschema.ExtSchema, error) { - return nil, nil -} - -func (v *BaseFFIParamValidator) GetMetaSchema() *jsonschema.Schema { - return jsonschema.MustCompileString("ffi.json", `{ - "$ref": "#/$defs/ffiParam", - "$defs": { - "integerTypeOptions": { - "type": "object", - "properties": { - "type": { - "type": "string", - "enum": [ - "integer", - "string" - ] - } - } - }, - "ffiParam": { - "oneOf": [ - { - "properties": { - "type": { - "type": [ - "string" - ], - "enum": [ - "boolean", - "integer", - "string", - "array", - "object" - ] - } - }, - "required": [ - "type" - ] - }, - { - "type": "object", - "properties": { - "oneOf": { - "type": "array", - "items": { - "$ref": "#/$defs/integerTypeOptions" - } - } - }, - "required": [ - "oneOf" - ] - } - ] - } - } - }`) -} - -func (v *BaseFFIParamValidator) GetExtensionName() string { - return "ffi" -} - -func NewFFISchemaCompiler() *jsonschema.Compiler { - c := jsonschema.NewCompiler() - c.Draft = jsonschema.Draft2020 - v := BaseFFIParamValidator{} - c.RegisterExtension(v.GetExtensionName(), v.GetMetaSchema(), v) - return c -} diff --git a/pkg/core/ffi_param_validator_test.go b/pkg/core/ffi_param_validator_test.go deleted file mode 100644 index a0ee719efa..0000000000 --- a/pkg/core/ffi_param_validator_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core - -import ( - "testing" - - "github.com/santhosh-tekuri/jsonschema/v5" - "github.com/stretchr/testify/assert" -) - -func TestGetBaseFFIParamValidator(t *testing.T) { - c := NewFFISchemaCompiler() - assert.NotNil(t, c) -} -func TestBaseFFIParamValidatorCompile(t *testing.T) { - v := BaseFFIParamValidator{} - c, err := v.Compile(jsonschema.CompilerContext{}, map[string]interface{}{}) - assert.Nil(t, c) - assert.NoError(t, err) -} diff --git a/pkg/core/ffi_test.go b/pkg/core/ffi_test.go deleted file mode 100644 index 7a06411585..0000000000 --- a/pkg/core/ffi_test.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright © 2021 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core - -import ( - "context" - "testing" - - "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/stretchr/testify/assert" -) - -func TestValidateFFI(t *testing.T) { - ffi := &FFI{ - Name: "math", - Namespace: "default", - Version: "v1.0.0", - Methods: []*FFIMethod{ - { - Name: "sum", - Params: []*FFIParam{ - { - Name: "x", - Schema: fftypes.JSONAnyPtr(`{"type": "integer"}, "details": {"type": "uint256"}`), - }, - { - Name: "y", - Schema: fftypes.JSONAnyPtr(`{"type": "integer"}, "details": {"type": "uint256"}`), - }, - }, - Returns: []*FFIParam{ - { - Name: "z", - Schema: fftypes.JSONAnyPtr(`{"type": "integer"}, "details": {"type": "uint256"}`), - }, - }, - }, - }, - Events: []*FFIEvent{ - { - FFIEventDefinition: FFIEventDefinition{ - Name: "sum", - Params: []*FFIParam{ - { - Name: "z", - Schema: fftypes.JSONAnyPtr(`{"type": "integer"}, "details": {"type": "uint256"}`), - }, - }, - }, - }, - }, - } - err := ffi.Validate(context.Background(), true) - assert.NoError(t, err) -} - -func TestValidateFFIBadVersion(t *testing.T) { - ffi := &FFI{ - Name: "math", - Namespace: "default", - Version: "*(&!$%^)", - } - err := ffi.Validate(context.Background(), true) - assert.Regexp(t, "FF00140", err) -} - -func TestValidateFFIBadName(t *testing.T) { - ffi := &FFI{ - Name: "(*%&#%)", - Namespace: "default", - Version: "v1.0.0", - } - err := ffi.Validate(context.Background(), true) - assert.Regexp(t, "FF00140", err) -} - -func TestValidateFFIBadNamespace(t *testing.T) { - ffi := &FFI{ - Name: "math", - Namespace: "", - Version: "v1.0.0", - } - err := ffi.Validate(context.Background(), true) - assert.Regexp(t, "FF00140", err) -} - -func TestFFIParamsScan(t *testing.T) { - params := &FFIParams{} - err := params.Scan([]byte(`[{"name": "x", "type": "integer", "internalType": "uint256"}]`)) - assert.NoError(t, err) -} - -func TestFFIParamsScanString(t *testing.T) { - params := &FFIParams{} - err := params.Scan(`[{"name": "x", "type": "integer", "internalType": "uint256"}]`) - assert.NoError(t, err) -} - -func TestFFIParamsScanNil(t *testing.T) { - params := &FFIParams{} - err := params.Scan(nil) - assert.Nil(t, err) -} - -func TestFFIParamsScanError(t *testing.T) { - params := &FFIParams{} - err := params.Scan(map[string]interface{}{"type": "not supported for scanning FFIParams"}) - assert.Regexp(t, "FF00105", err) -} - -func TestFFIParamsValue(t *testing.T) { - params := &FFIParams{ - &FFIParam{ - Name: "x", - Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), - }, - } - - val, err := params.Value() - assert.NoError(t, err) - assert.Equal(t, []byte(`[{"name":"x","schema":{"type":"integer","details":{"type":"uint256"}}}]`), val) -} - -func TestFFITopic(t *testing.T) { - ffi := &FFI{ - Namespace: "ns1", - } - assert.Equal(t, "01a982a7251400a7ec64fccce6febee3942a56e37967fa2ba26d7d6f43523c82", ffi.Topic()) -} - -func TestFFISetBroadCastMessage(t *testing.T) { - msgID := fftypes.NewUUID() - ffi := &FFI{} - ffi.SetBroadcastMessage(msgID) - assert.Equal(t, ffi.Message, msgID) -} diff --git a/pkg/core/group.go b/pkg/core/group.go index 3fc446a9ac..9e30ab8d72 100644 --- a/pkg/core/group.go +++ b/pkg/core/group.go @@ -63,12 +63,12 @@ func (man *GroupIdentity) Hash() *fftypes.Bytes32 { } func (group *Group) Validate(ctx context.Context, existing bool) (err error) { - if err = ValidateFFNameField(ctx, group.Namespace, "namespace"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, group.Namespace, "namespace"); err != nil { return err } // We allow a blank name for a group (for auto creation) if group.Name != "" { - if err = ValidateFFNameFieldNoUUID(ctx, group.Name, "name"); err != nil { + if err = fftypes.ValidateFFNameFieldNoUUID(ctx, group.Name, "name"); err != nil { return err } } @@ -80,7 +80,7 @@ func (group *Group) Validate(ctx context.Context, existing bool) (err error) { if r.Identity == "" { return i18n.NewError(ctx, i18n.MsgEmptyMemberIdentity, i) } - if err = ValidateLength(ctx, r.Identity, "identity", 1024); err != nil { + if err = fftypes.ValidateLength(ctx, r.Identity, "identity", 1024); err != nil { return err } if r.Node == nil { diff --git a/pkg/core/identity.go b/pkg/core/identity.go index a64761deee..7dba1171aa 100644 --- a/pkg/core/identity.go +++ b/pkg/core/identity.go @@ -166,10 +166,10 @@ func (i *IdentityBase) Validate(ctx context.Context) (err error) { if i.ID == nil { return i18n.NewError(ctx, i18n.MsgNilID) } - if err = ValidateFFNameFieldNoUUID(ctx, i.Namespace, "namespace"); err != nil { + if err = fftypes.ValidateFFNameFieldNoUUID(ctx, i.Namespace, "namespace"); err != nil { return err } - if err = ValidateFFNameFieldNoUUID(ctx, i.Name, "name"); err != nil { + if err = fftypes.ValidateFFNameFieldNoUUID(ctx, i.Name, "name"); err != nil { return err } @@ -231,7 +231,7 @@ func (identity *Identity) Validate(ctx context.Context) (err error) { if err = identity.IdentityBase.Validate(ctx); err != nil { return err } - if err = ValidateLength(ctx, identity.Description, "description", 4096); err != nil { + if err = fftypes.ValidateLength(ctx, identity.Description, "description", 4096); err != nil { return err } return nil diff --git a/pkg/core/message.go b/pkg/core/message.go index 7fe672ff05..763937e6e8 100644 --- a/pkg/core/message.go +++ b/pkg/core/message.go @@ -229,7 +229,7 @@ func (m *Message) VerifyFields(ctx context.Context) error { return err } if m.Header.Tag != "" { - if err := ValidateFFNameField(ctx, m.Header.Tag, "header.tag"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, m.Header.Tag, "header.tag"); err != nil { return err } } diff --git a/pkg/core/namespace.go b/pkg/core/namespace.go index 1704e9c2c3..c158a617aa 100644 --- a/pkg/core/namespace.go +++ b/pkg/core/namespace.go @@ -18,7 +18,6 @@ package core import ( "context" - "crypto/sha256" "database/sql/driver" "encoding/json" @@ -74,10 +73,10 @@ type NetworkAction struct { } func (ns *Namespace) Validate(ctx context.Context, existing bool) (err error) { - if err = ValidateFFNameField(ctx, ns.Name, "name"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, ns.Name, "name"); err != nil { return err } - if err = ValidateLength(ctx, ns.Description, "description", 4096); err != nil { + if err = fftypes.ValidateLength(ctx, ns.Description, "description", 4096); err != nil { return err } if existing { @@ -88,18 +87,8 @@ func (ns *Namespace) Validate(ctx context.Context, existing bool) (err error) { return nil } -func typeNamespaceNameTopicHash(objType string, ns string, name string) string { - // Topic generation function for ordering anything with a type, namespace and name. - // Means all messages racing for this name will be consistently ordered by all parties. - h := sha256.New() - h.Write([]byte(objType)) - h.Write([]byte(ns)) - h.Write([]byte(name)) - return fftypes.HashResult(h).String() -} - func (ns *Namespace) Topic() string { - return typeNamespaceNameTopicHash("namespace", ns.Name, "") + return fftypes.TypeNamespaceNameTopicHash("namespace", ns.Name, "") } func (ns *Namespace) SetBroadcastMessage(msgID *fftypes.UUID) { diff --git a/pkg/core/operation.go b/pkg/core/operation.go index 4d145f491c..95da0cb04b 100644 --- a/pkg/core/operation.go +++ b/pkg/core/operation.go @@ -133,7 +133,7 @@ func ParseNamespacedOpID(ctx context.Context, nsIDStr string) (string, *fftypes. } ns := nsIDSplit[0] uuidStr := nsIDSplit[1] - if err := ValidateFFNameField(ctx, ns, "namespace"); err != nil { + if err := fftypes.ValidateFFNameField(ctx, ns, "namespace"); err != nil { return "", nil, err } u, err := fftypes.ParseUUID(ctx, uuidStr) diff --git a/pkg/core/stringarray.go b/pkg/core/stringarray.go index ee40585d0f..4b32ab69f0 100644 --- a/pkg/core/stringarray.go +++ b/pkg/core/stringarray.go @@ -23,6 +23,7 @@ import ( "sort" "strings" + "github.com/hyperledger/firefly-common/pkg/fftypes" "github.com/hyperledger/firefly-common/pkg/i18n" ) @@ -97,11 +98,11 @@ func (sa FFStringArray) Validate(ctx context.Context, fieldName string, isName b dupCheck[n] = true totalLength += len(n) if isName { - if err := ValidateFFNameField(ctx, n, fmt.Sprintf("%s[%d]", fieldName, i)); err != nil { + if err := fftypes.ValidateFFNameField(ctx, n, fmt.Sprintf("%s[%d]", fieldName, i)); err != nil { return err } } else { - if err := ValidateSafeCharsOnly(ctx, n, fmt.Sprintf("%s[%d]", fieldName, i)); err != nil { + if err := fftypes.ValidateSafeCharsOnly(ctx, n, fmt.Sprintf("%s[%d]", fieldName, i)); err != nil { return err } } diff --git a/pkg/core/tokenpool.go b/pkg/core/tokenpool.go index e9e30273cc..b8cf10b43b 100644 --- a/pkg/core/tokenpool.go +++ b/pkg/core/tokenpool.go @@ -66,17 +66,17 @@ type TokenPoolAnnouncement struct { } func (t *TokenPool) Validate(ctx context.Context) (err error) { - if err = ValidateFFNameField(ctx, t.Namespace, "namespace"); err != nil { + if err = fftypes.ValidateFFNameField(ctx, t.Namespace, "namespace"); err != nil { return err } - if err = ValidateFFNameFieldNoUUID(ctx, t.Name, "name"); err != nil { + if err = fftypes.ValidateFFNameFieldNoUUID(ctx, t.Name, "name"); err != nil { return err } return nil } func (t *TokenPoolAnnouncement) Topic() string { - return typeNamespaceNameTopicHash("tokenpool", t.Pool.Namespace, t.Pool.Name) + return fftypes.TypeNamespaceNameTopicHash("tokenpool", t.Pool.Namespace, t.Pool.Name) } func (t *TokenPoolAnnouncement) SetBroadcastMessage(msgID *fftypes.UUID) { diff --git a/pkg/core/validations.go b/pkg/core/validations.go deleted file mode 100644 index 18ee13609d..0000000000 --- a/pkg/core/validations.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2022 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core - -import ( - "context" - "regexp" - - "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/hyperledger/firefly-common/pkg/i18n" -) - -var ( - ffNameValidator = regexp.MustCompile(`^[0-9a-zA-Z]([0-9a-zA-Z._-]{0,62}[0-9a-zA-Z])?$`) - ffSafeCharsValidator = regexp.MustCompile(`^[0-9a-zA-Z._-]*$`) -) - -func ValidateSafeCharsOnly(ctx context.Context, str string, fieldName string) error { - if !ffSafeCharsValidator.MatchString(str) { - return i18n.NewError(ctx, i18n.MsgSafeCharsOnly, fieldName) - } - return nil -} - -func ValidateFFNameField(ctx context.Context, str string, fieldName string) error { - if !ffNameValidator.MatchString(str) { - return i18n.NewError(ctx, i18n.MsgInvalidName, fieldName) - } - return nil -} - -func ValidateFFNameFieldNoUUID(ctx context.Context, str string, fieldName string) error { - if _, err := fftypes.ParseUUID(ctx, str); err == nil { - // Name must not be a UUID - return i18n.NewError(ctx, i18n.MsgNoUUID, fieldName) - } - return ValidateFFNameField(ctx, str, fieldName) -} - -func ValidateLength(ctx context.Context, str string, fieldName string, max int) error { - if len([]byte(str)) > max { - return i18n.NewError(ctx, i18n.MsgFieldTooLong, fieldName, max) - } - return nil -} diff --git a/pkg/core/validations_test.go b/pkg/core/validations_test.go deleted file mode 100644 index 6c5fa6b0f8..0000000000 --- a/pkg/core/validations_test.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright © 2021 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package core - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestValidateFFNameField(t *testing.T) { - - err := ValidateFFNameField(context.Background(), "_badstart", "badField") - assert.Regexp(t, "FF00140.*badField", err) - - err = ValidateFFNameField(context.Background(), "badend_", "badField") - assert.Regexp(t, "FF00140.*badField", err) - - err = ValidateFFNameField(context.Background(), "0123456789_123456789-123456789.123456789-123456789_1234567890123", "badField") - assert.NoError(t, err) - - err = ValidateFFNameField(context.Background(), "0123456789_123456789-123456789.123456789-123456789_12345678901234", "badField") - assert.Regexp(t, "FF00140.*badField", err) - - err = ValidateFFNameField(context.Background(), "af34658e-a728-4b21-b9cf-8451f07be065", "badField") - assert.NoError(t, err) - - err = ValidateFFNameFieldNoUUID(context.Background(), "af34658e-a728-4b21-b9cf-8451f07be065", "badField") - assert.Regexp(t, "FF00141.*badField", err) - -} - -func TestValidateLength(t *testing.T) { - - err := ValidateLength(context.Background(), "long string", "test", 5) - assert.Regexp(t, "FF00135.*test", err) - - err = ValidateLength(context.Background(), "short string", "test", 50) - assert.NoError(t, err) - -} diff --git a/pkg/database/plugin.go b/pkg/database/plugin.go index 07cb114965..68a6533a2f 100644 --- a/pkg/database/plugin.go +++ b/pkg/database/plugin.go @@ -452,23 +452,23 @@ type iTokenApprovalCollection interface { } type iFFICollection interface { - UpsertFFI(ctx context.Context, cd *core.FFI) error - GetFFIs(ctx context.Context, ns string, filter Filter) ([]*core.FFI, *FilterResult, error) - GetFFIByID(ctx context.Context, id *fftypes.UUID) (*core.FFI, error) - GetFFI(ctx context.Context, ns, name, version string) (*core.FFI, error) + UpsertFFI(ctx context.Context, cd *fftypes.FFI) error + GetFFIs(ctx context.Context, ns string, filter Filter) ([]*fftypes.FFI, *FilterResult, error) + GetFFIByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFI, error) + GetFFI(ctx context.Context, ns, name, version string) (*fftypes.FFI, error) } type iFFIMethodCollection interface { - UpsertFFIMethod(ctx context.Context, method *core.FFIMethod) error - GetFFIMethod(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*core.FFIMethod, error) - GetFFIMethods(ctx context.Context, filter Filter) (methods []*core.FFIMethod, res *FilterResult, err error) + UpsertFFIMethod(ctx context.Context, method *fftypes.FFIMethod) error + GetFFIMethod(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*fftypes.FFIMethod, error) + GetFFIMethods(ctx context.Context, filter Filter) (methods []*fftypes.FFIMethod, res *FilterResult, err error) } type iFFIEventCollection interface { - UpsertFFIEvent(ctx context.Context, method *core.FFIEvent) error - GetFFIEvent(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*core.FFIEvent, error) - GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*core.FFIEvent, error) - GetFFIEvents(ctx context.Context, filter Filter) (events []*core.FFIEvent, res *FilterResult, err error) + UpsertFFIEvent(ctx context.Context, method *fftypes.FFIEvent) error + GetFFIEvent(ctx context.Context, ns string, interfaceID *fftypes.UUID, pathName string) (*fftypes.FFIEvent, error) + GetFFIEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.FFIEvent, error) + GetFFIEvents(ctx context.Context, filter Filter) (events []*fftypes.FFIEvent, res *FilterResult, err error) } type iContractAPICollection interface { diff --git a/test/e2e/ethereum_contract_test.go b/test/e2e/ethereum_contract_test.go index d794bcb6f6..8e58ff894e 100644 --- a/test/e2e/ethereum_contract_test.go +++ b/test/e2e/ethereum_contract_test.go @@ -47,11 +47,11 @@ type simpleStorageBody struct { NewValue string `json:"newValue"` } -func simpleStorageFFIChanged() *core.FFIEvent { - return &core.FFIEvent{ - FFIEventDefinition: core.FFIEventDefinition{ +func simpleStorageFFIChanged() *fftypes.FFIEvent { + return &fftypes.FFIEvent{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "Changed", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "_from", Schema: fftypes.JSONAnyPtr(`{"type": "string", "details": {"type": "address", "indexed": true}}`), @@ -65,38 +65,38 @@ func simpleStorageFFIChanged() *core.FFIEvent { } } -func simpleStorageFFI() *core.FFI { - return &core.FFI{ +func simpleStorageFFI() *fftypes.FFI { + return &fftypes.FFI{ Name: "SimpleStorage", Version: contractVersion, - Methods: []*core.FFIMethod{ + Methods: []*fftypes.FFIMethod{ simpleStorageFFISet(), simpleStorageFFIGet(), }, - Events: []*core.FFIEvent{ + Events: []*fftypes.FFIEvent{ simpleStorageFFIChanged(), }, } } -func simpleStorageFFISet() *core.FFIMethod { - return &core.FFIMethod{ +func simpleStorageFFISet() *fftypes.FFIMethod { + return &fftypes.FFIMethod{ Name: "set", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "newValue", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), }, }, - Returns: core.FFIParams{}, + Returns: fftypes.FFIParams{}, } } -func simpleStorageFFIGet() *core.FFIMethod { - return &core.FFIMethod{ +func simpleStorageFFIGet() *fftypes.FFIMethod { + return &fftypes.FFIMethod{ Name: "get", - Params: core.FFIParams{}, - Returns: core.FFIParams{ + Params: fftypes.FFIParams{}, + Returns: fftypes.FFIParams{ { Name: "output", Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), @@ -195,7 +195,7 @@ func (suite *EthereumContractTestSuite) TestFFIInvokeMethod() { received1 := wsReader(suite.testState.ws1, true) - ffiReference := &core.FFIReference{ + ffiReference := &fftypes.FFIReference{ ID: suite.interfaceID, } listener := CreateFFIContractListener(suite.T(), suite.testState.client1, ffiReference, "Changed", &fftypes.JSONObject{ @@ -255,7 +255,7 @@ func (suite *EthereumContractTestSuite) TestContractAPIMethod() { received1 := wsReader(suite.testState.ws1, true) APIName := fftypes.NewUUID().String() - ffiReference := &core.FFIReference{ + ffiReference := &fftypes.FFIReference{ ID: suite.interfaceID, } diff --git a/test/e2e/fabric_contract_test.go b/test/e2e/fabric_contract_test.go index bbed1341bb..3f90af89e5 100644 --- a/test/e2e/fabric_contract_test.go +++ b/test/e2e/fabric_contract_test.go @@ -45,35 +45,35 @@ type createAssetBody struct { Args []string `json:"args"` } -var assetCreatedEvent = &core.FFIEvent{ - FFIEventDefinition: core.FFIEventDefinition{ +var assetCreatedEvent = &fftypes.FFIEvent{ + FFIEventDefinition: fftypes.FFIEventDefinition{ Name: "AssetCreated", }, } -func assetManagerCreateAsset() *core.FFIMethod { - return &core.FFIMethod{ +func assetManagerCreateAsset() *fftypes.FFIMethod { + return &fftypes.FFIMethod{ Name: "CreateAsset", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "name", Schema: fftypes.JSONAnyPtr(`{"type": "string"}`), }, }, - Returns: core.FFIParams{}, + Returns: fftypes.FFIParams{}, } } -func assetManagerGetAsset() *core.FFIMethod { - return &core.FFIMethod{ +func assetManagerGetAsset() *fftypes.FFIMethod { + return &fftypes.FFIMethod{ Name: "GetAsset", - Params: core.FFIParams{ + Params: fftypes.FFIParams{ { Name: "name", Schema: fftypes.JSONAnyPtr(`{"type": "string"}`), }, }, - Returns: core.FFIParams{ + Returns: fftypes.FFIParams{ { Name: "name", Schema: fftypes.JSONAnyPtr(`{"type": "string"}`), diff --git a/test/e2e/restclient_test.go b/test/e2e/restclient_test.go index db80aa05fb..cc93b36736 100644 --- a/test/e2e/restclient_test.go +++ b/test/e2e/restclient_test.go @@ -623,7 +623,7 @@ func GetTokenBalance(t *testing.T, client *resty.Client, poolID *fftypes.UUID, t return accounts[0] } -func CreateContractListener(t *testing.T, client *resty.Client, event *core.FFIEvent, location *fftypes.JSONObject) *core.ContractListener { +func CreateContractListener(t *testing.T, client *resty.Client, event *fftypes.FFIEvent, location *fftypes.JSONObject) *core.ContractListener { body := core.ContractListenerInput{ ContractListener: core.ContractListener{ Location: fftypes.JSONAnyPtr(location.String()), @@ -644,7 +644,7 @@ func CreateContractListener(t *testing.T, client *resty.Client, event *core.FFIE return &sub } -func CreateFFIContractListener(t *testing.T, client *resty.Client, ffiReference *core.FFIReference, eventPath string, location *fftypes.JSONObject) *core.ContractListener { +func CreateFFIContractListener(t *testing.T, client *resty.Client, ffiReference *fftypes.FFIReference, eventPath string, location *fftypes.JSONObject) *core.ContractListener { body := core.ContractListenerInput{ ContractListener: core.ContractListener{ Location: fftypes.JSONAnyPtr(location.String()), @@ -718,7 +718,7 @@ func QueryContractMethod(t *testing.T, client *resty.Client, req *core.ContractC return res, err } -func CreateFFI(t *testing.T, client *resty.Client, ffi *core.FFI) (interface{}, error) { +func CreateFFI(t *testing.T, client *resty.Client, ffi *fftypes.FFI) (interface{}, error) { var res interface{} path := urlContractInterface resp, err := client.R(). @@ -731,7 +731,7 @@ func CreateFFI(t *testing.T, client *resty.Client, ffi *core.FFI) (interface{}, return res, err } -func CreateContractAPI(t *testing.T, client *resty.Client, name string, FFIReference *core.FFIReference, location *fftypes.JSONAny) (interface{}, error) { +func CreateContractAPI(t *testing.T, client *resty.Client, name string, FFIReference *fftypes.FFIReference, location *fftypes.JSONAny) (interface{}, error) { apiReqBody := &core.ContractAPI{ Name: name, Interface: FFIReference, From 129acb587b02cdac942932c2fcfa54968e6a8db8 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 28 Jun 2022 12:04:10 -0400 Subject: [PATCH 2/3] Update to use latest common and signer libraries Signed-off-by: Nicko Guyer --- go.mod | 6 +- go.sum | 6 +- internal/apiserver/ffi2swagger.go | 67 ++++++++++--------- internal/apiserver/ffi2swagger_test.go | 21 ++++-- internal/blockchain/ethereum/ethereum.go | 14 ++-- internal/contracts/manager_test.go | 43 ++++++++++-- .../solidity_firefly/hardhat.config.ts | 4 -- 7 files changed, 104 insertions(+), 57 deletions(-) diff --git a/go.mod b/go.mod index f09c04d97a..611e00382b 100644 --- a/go.mod +++ b/go.mod @@ -13,8 +13,8 @@ require ( github.com/golang-migrate/migrate/v4 v4.15.2 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 - github.com/hyperledger/firefly-common v0.1.11-0.20220616154518-160b5cf404cc - github.com/hyperledger/firefly-signer v0.9.11-0.20220617121121-907f2dd3b6fd + github.com/hyperledger/firefly-common v0.1.13 + github.com/hyperledger/firefly-signer v0.9.11 github.com/jarcoal/httpmock v1.1.0 github.com/karlseguin/ccache v2.0.3+incompatible github.com/lib/pq v1.10.6 @@ -84,3 +84,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/hyperledger/firefly-signer => ../firefly-signer diff --git a/go.sum b/go.sum index 70d9bf4f04..e52e01c8dc 100644 --- a/go.sum +++ b/go.sum @@ -726,10 +726,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hyperledger/firefly-common v0.1.11-0.20220616154518-160b5cf404cc h1:QLDIYiK9+CTIQ5a2F6zLbjIsxW1+VW4BGNBIkwTYQ9Q= -github.com/hyperledger/firefly-common v0.1.11-0.20220616154518-160b5cf404cc/go.mod h1:2NqPi5Ud9H6rSlZXkLbotxW7z4EAD89p3/8oNOpm9Gs= -github.com/hyperledger/firefly-signer v0.9.11-0.20220617121121-907f2dd3b6fd h1:dZiUGENFiU3i88C+smXY9ANUopBvjFaaCGRQbj55uKU= -github.com/hyperledger/firefly-signer v0.9.11-0.20220617121121-907f2dd3b6fd/go.mod h1:ycTpoDzq4/NS3F0Kq4u1ISdSW62xx6pMPMd3SkmB1UQ= +github.com/hyperledger/firefly-common v0.1.13 h1:eNK99U9FV43u1F46MM0mPuXT4Xn++orghpoTIIPsmwo= +github.com/hyperledger/firefly-common v0.1.13/go.mod h1:2NqPi5Ud9H6rSlZXkLbotxW7z4EAD89p3/8oNOpm9Gs= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/internal/apiserver/ffi2swagger.go b/internal/apiserver/ffi2swagger.go index d72353de62..f639f9cc08 100644 --- a/internal/apiserver/ffi2swagger.go +++ b/internal/apiserver/ffi2swagger.go @@ -95,20 +95,28 @@ func (og *ffiSwaggerGen) addMethod(routes []*ffapi.Route, method *fftypes.FFIMet description = fmt.Sprintf("%s\n\n%s:\n\n%s", description, additionalDetailsHeader, buildDetailsTable(ctx, method.Details)) } routes = append(routes, &ffapi.Route{ - Name: fmt.Sprintf("invoke_%s", method.Pathname), - Path: fmt.Sprintf("invoke/%s", method.Pathname), // must match a route defined in apiserver routes! - Method: http.MethodPost, - JSONInputSchema: func(ctx context.Context) string { return contractCallJSONSchema(&method.Params, hasLocation).String() }, - JSONOutputSchema: func(ctx context.Context) string { return ffiParamsJSONSchema(&method.Returns).String() }, + Name: fmt.Sprintf("invoke_%s", method.Pathname), + Path: fmt.Sprintf("invoke/%s", method.Pathname), // must match a route defined in apiserver routes! + Method: http.MethodPost, + JSONInputSchema: func(ctx context.Context, schemaGen ffapi.SchemaGenerator) (*openapi3.SchemaRef, error) { + return contractJSONSchema(&method.Params, hasLocation) + }, + JSONOutputSchema: func(ctx context.Context, schemaGen ffapi.SchemaGenerator) (*openapi3.SchemaRef, error) { + return contractJSONSchema(&method.Returns, true) + }, JSONOutputCodes: []int{http.StatusOK}, PreTranslatedDescription: description, }) routes = append(routes, &ffapi.Route{ - Name: fmt.Sprintf("query_%s", method.Pathname), - Path: fmt.Sprintf("query/%s", method.Pathname), // must match a route defined in apiserver routes! - Method: http.MethodPost, - JSONInputSchema: func(ctx context.Context) string { return contractCallJSONSchema(&method.Params, hasLocation).String() }, - JSONOutputSchema: func(ctx context.Context) string { return ffiParamsJSONSchema(&method.Returns).String() }, + Name: fmt.Sprintf("query_%s", method.Pathname), + Path: fmt.Sprintf("query/%s", method.Pathname), // must match a route defined in apiserver routes! + Method: http.MethodPost, + JSONInputSchema: func(ctx context.Context, schemaGen ffapi.SchemaGenerator) (*openapi3.SchemaRef, error) { + return contractJSONSchema(&method.Params, hasLocation) + }, + JSONOutputSchema: func(ctx context.Context, schemaGen ffapi.SchemaGenerator) (*openapi3.SchemaRef, error) { + return contractJSONSchema(&method.Returns, true) + }, JSONOutputCodes: []int{http.StatusOK}, PreTranslatedDescription: description, }) @@ -154,9 +162,17 @@ func (og *ffiSwaggerGen) addEvent(routes []*ffapi.Route, event *fftypes.FFIEvent * Parse the FFI and build a corresponding JSON Schema to describe the request body for "invoke". * Returns the JSON Schema as an `fftypes.JSONObject`. */ -func contractCallJSONSchema(params *fftypes.FFIParams, hasLocation bool) *fftypes.JSONObject { +func contractJSONSchema(params *fftypes.FFIParams, hasLocation bool) (*openapi3.SchemaRef, error) { + paramSchema := make(fftypes.JSONObject, len(*params)) + for _, param := range *params { + paramSchema[param.Name] = param.Schema + } + inputSchema := fftypes.JSONObject{ + "type": "object", + "properties": paramSchema, + } properties := fftypes.JSONObject{ - "input": ffiParamsJSONSchema(params), + "input": inputSchema, "options": fftypes.JSONObject{ "type": "object", }, @@ -164,29 +180,20 @@ func contractCallJSONSchema(params *fftypes.FFIParams, hasLocation bool) *fftype if !hasLocation { properties["location"] = fftypes.JSONAnyPtr(`{}`) } - return &fftypes.JSONObject{ + schema := fftypes.JSONObject{ "type": "object", "properties": properties, } -} - -func ffiParamsJSONSchema(params *fftypes.FFIParams) *fftypes.JSONObject { - out := make(fftypes.JSONObject, len(*params)) - for _, param := range *params { - out[param.Name] = ffiParamJSONSchema(param) - } - return &fftypes.JSONObject{ - "type": "object", - "properties": out, + b, err := json.Marshal(schema) + if err != nil { + return nil, err } -} - -func ffiParamJSONSchema(param *fftypes.FFIParam) *fftypes.JSONObject { - out := fftypes.JSONObject{} - if err := json.Unmarshal(param.Schema.Bytes(), &out); err == nil { - return &out + s := openapi3.NewSchema() + err = s.UnmarshalJSON(b) + if err != nil { + return nil, err } - return nil + return openapi3.NewSchemaRef("", s), nil } func buildDetailsTable(ctx context.Context, details map[string]interface{}) string { diff --git a/internal/apiserver/ffi2swagger_test.go b/internal/apiserver/ffi2swagger_test.go index 1269c2c0dd..54dfd4e02f 100644 --- a/internal/apiserver/ffi2swagger_test.go +++ b/internal/apiserver/ffi2swagger_test.go @@ -186,10 +186,21 @@ func TestGenerateWithLocation(t *testing.T) { } func TestFFIParamBadSchema(t *testing.T) { - param := &fftypes.FFIParam{ - Name: "test", - Schema: fftypes.JSONAnyPtr(`{`), + params := &fftypes.FFIParams{ + &fftypes.FFIParam{ + Name: "test", + Schema: fftypes.JSONAnyPtr(`{`), + }, + } + _, err := contractJSONSchema(params, true) + assert.Error(t, err) + + params = &fftypes.FFIParams{ + &fftypes.FFIParam{ + Name: "test", + Schema: fftypes.JSONAnyPtr(`{"type": false}`), + }, } - r := ffiParamJSONSchema(param) - assert.Nil(t, r) + _, err = contractJSONSchema(params, true) + assert.Error(t, err) } diff --git a/internal/blockchain/ethereum/ethereum.go b/internal/blockchain/ethereum/ethereum.go index 791f0529dd..891a6ecf01 100644 --- a/internal/blockchain/ethereum/ethereum.go +++ b/internal/blockchain/ethereum/ethereum.go @@ -34,7 +34,7 @@ import ( "github.com/hyperledger/firefly-common/pkg/log" "github.com/hyperledger/firefly-common/pkg/wsclient" "github.com/hyperledger/firefly-signer/pkg/abi" - "github.com/hyperledger/firefly-signer/pkg/ffi" + "github.com/hyperledger/firefly-signer/pkg/ffi2abi" "github.com/hyperledger/firefly/internal/coremsgs" "github.com/hyperledger/firefly/internal/metrics" "github.com/hyperledger/firefly/pkg/blockchain" @@ -779,7 +779,7 @@ func (e *Ethereum) AddContractListener(ctx context.Context, listener *core.Contr if err != nil { return err } - abi, err := ffi.ConvertFFIEventDefinitionToABI(ctx, &listener.Event.FFIEventDefinition) + abi, err := ffi2abi.ConvertFFIEventDefinitionToABI(ctx, &listener.Event.FFIEventDefinition) if err != nil { return i18n.WrapError(ctx, err, coremsgs.MsgContractParamInvalid) } @@ -802,20 +802,20 @@ func (e *Ethereum) DeleteContractListener(ctx context.Context, subscription *cor } func (e *Ethereum) GetFFIParamValidator(ctx context.Context) (fftypes.FFIParamValidator, error) { - return &ffi.ParamValidator{}, nil + return &ffi2abi.ParamValidator{}, nil } func (e *Ethereum) GenerateEventSignature(ctx context.Context, event *fftypes.FFIEventDefinition) string { - abi, err := ffi.ConvertFFIEventDefinitionToABI(ctx, event) + abi, err := ffi2abi.ConvertFFIEventDefinitionToABI(ctx, event) if err != nil { return "" } - return ffi.ABIMethodToSignature(abi) + return ffi2abi.ABIMethodToSignature(abi) } func (e *Ethereum) prepareRequest(ctx context.Context, method *fftypes.FFIMethod, input map[string]interface{}) (*abi.Entry, []interface{}, error) { orderedInput := make([]interface{}, len(method.Params)) - abi, err := ffi.ConvertFFIMethodToABI(ctx, method) + abi, err := ffi2abi.ConvertFFIMethodToABI(ctx, method) if err != nil { return abi, orderedInput, err } @@ -849,7 +849,7 @@ func (e *Ethereum) GenerateFFI(ctx context.Context, generationRequest *fftypes.F if len(*input.ABI) == 0 { return nil, i18n.NewError(ctx, coremsgs.MsgFFIGenerationFailed, "ABI is empty") } - return ffi.ConvertABIToFFI(ctx, generationRequest.Namespace, generationRequest.Name, generationRequest.Version, generationRequest.Description, input.ABI) + return ffi2abi.ConvertABIToFFI(ctx, generationRequest.Namespace, generationRequest.Name, generationRequest.Version, generationRequest.Description, input.ABI) } func (e *Ethereum) getNetworkVersion(ctx context.Context, address string) (int, error) { diff --git a/internal/contracts/manager_test.go b/internal/contracts/manager_test.go index ee52e796ce..74dda82b35 100644 --- a/internal/contracts/manager_test.go +++ b/internal/contracts/manager_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/hyperledger/firefly-common/pkg/fftypes" - "github.com/hyperledger/firefly-signer/pkg/ffi" + "github.com/hyperledger/firefly-signer/pkg/ffi2abi" "github.com/hyperledger/firefly/internal/identity" "github.com/hyperledger/firefly/internal/syncasync" "github.com/hyperledger/firefly/internal/txcommon" @@ -99,7 +99,7 @@ func TestNewContractManagerFFISchemaLoader(t *testing.T) { mom := &operationmocks.Manager{} txHelper := txcommon.NewTransactionHelper(mdi, mdm) msa := &syncasyncmocks.Bridge{} - mbi.On("GetFFIParamValidator", mock.Anything).Return(&ffi.ParamValidator{}, nil) + mbi.On("GetFFIParamValidator", mock.Anything).Return(&ffi2abi.ParamValidator{}, nil) mom.On("RegisterHandler", mock.Anything, mock.Anything, mock.Anything) _, err := NewContractManager(context.Background(), mdi, mbm, mim, mbi, mom, txHelper, msa) assert.NoError(t, err) @@ -164,7 +164,7 @@ func TestBroadcastFFIInvalid(t *testing.T) { Params: []*fftypes.FFIParam{ { Name: "x", - Schema: fftypes.JSONAnyPtr(`{"type": "number"}`), + Schema: fftypes.JSONAnyPtr(`{"type": "null"}`), }, }, }, @@ -316,6 +316,39 @@ func TestValidateInvokeContractRequestInputWrongType(t *testing.T) { } func TestValidateInvokeContractRequestInvalidParam(t *testing.T) { + cm := newTestContractManager() + req := &core.ContractCallRequest{ + Type: core.CallTypeInvoke, + Method: &fftypes.FFIMethod{ + Name: "sum", + Params: []*fftypes.FFIParam{ + { + Name: "x", + Schema: fftypes.JSONAnyPtr(`{"type": "null", "details": {"type": "uint256"}}`), + }, + { + Name: "y", + Schema: fftypes.JSONAnyPtr(`{"type": "integer", "details": {"type": "uint256"}}`), + }, + }, + Returns: []*fftypes.FFIParam{ + { + Name: "z", + Schema: fftypes.JSONAnyPtr(`{"type": "integer"}`), + }, + }, + }, + Input: map[string]interface{}{ + "x": float64(1), + "y": float64(2), + }, + } + + err := cm.validateInvokeContractRequest(context.Background(), req) + assert.Regexp(t, "does not validate", err) +} + +func TestValidateInvokeContractRequestInvalidReturn(t *testing.T) { cm := newTestContractManager() req := &core.ContractCallRequest{ Type: core.CallTypeInvoke, @@ -334,7 +367,7 @@ func TestValidateInvokeContractRequestInvalidParam(t *testing.T) { Returns: []*fftypes.FFIParam{ { Name: "z", - Schema: fftypes.JSONAnyPtr(`{"type": "number"}`), + Schema: fftypes.JSONAnyPtr(`{"type": "null"}`), }, }, }, @@ -941,7 +974,7 @@ func TestAddContractListenerValidateFail(t *testing.T) { Params: fftypes.FFIParams{ { Name: "value", - Schema: fftypes.JSONAnyPtr(`{"type": "number"}`), + Schema: fftypes.JSONAnyPtr(`{"type": "null"}`), }, }, }, diff --git a/smart_contracts/ethereum/solidity_firefly/hardhat.config.ts b/smart_contracts/ethereum/solidity_firefly/hardhat.config.ts index ac5b2cb565..0ac4264742 100644 --- a/smart_contracts/ethereum/solidity_firefly/hardhat.config.ts +++ b/smart_contracts/ethereum/solidity_firefly/hardhat.config.ts @@ -14,10 +14,6 @@ const config: HardhatUserConfig = { networks: { 'firefly-cli': { url: "http://127.0.0.1:5100" - }, - rinkeby: { - url: `https://rinkeby.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, - accounts: [`${process.env.RINKEBY_PRIVATE_KEY}`] } }, gasReporter: { From bf34a71131e50209ea0a95193730767a98bf59c4 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Thu, 7 Jul 2022 12:06:19 -0400 Subject: [PATCH 3/3] Update go.mod Signed-off-by: Nicko Guyer --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 611e00382b..e783af3b4b 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 github.com/hyperledger/firefly-common v0.1.13 - github.com/hyperledger/firefly-signer v0.9.11 + github.com/hyperledger/firefly-signer v0.9.12 github.com/jarcoal/httpmock v1.1.0 github.com/karlseguin/ccache v2.0.3+incompatible github.com/lib/pq v1.10.6 @@ -84,5 +84,3 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/hyperledger/firefly-signer => ../firefly-signer diff --git a/go.sum b/go.sum index e52e01c8dc..6058af9802 100644 --- a/go.sum +++ b/go.sum @@ -728,6 +728,8 @@ github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpT github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hyperledger/firefly-common v0.1.13 h1:eNK99U9FV43u1F46MM0mPuXT4Xn++orghpoTIIPsmwo= github.com/hyperledger/firefly-common v0.1.13/go.mod h1:2NqPi5Ud9H6rSlZXkLbotxW7z4EAD89p3/8oNOpm9Gs= +github.com/hyperledger/firefly-signer v0.9.12 h1:pCPiGHx1+MbTsIQuRkoQmfWxvpcvtGHVavls0NnH0po= +github.com/hyperledger/firefly-signer v0.9.12/go.mod h1:GPQRUZOFOAjkLmg8GDjZUjEdUD0gcar+CSVhwltIwyw= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=