From d4bed519203ad77a2ef4e83ce8d18de36734fd1c Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 8 Nov 2022 11:18:40 -0500 Subject: [PATCH 1/2] Add enhancements to Depoy Contract API * Add error mapping for unsupported blockchain connectors * Add new operation events to documentation * Remove unused fftm code in Ethereum plugin Signed-off-by: Nicko Guyer --- .../types/_includes/event_description.md | 6 +++-- internal/blockchain/ethereum/ethereum.go | 23 ++++++------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/docs/reference/types/_includes/event_description.md b/docs/reference/types/_includes/event_description.md index abecba752d..cd1b1e7d8e 100644 --- a/docs/reference/types/_includes/event_description.md +++ b/docs/reference/types/_includes/event_description.md @@ -72,8 +72,8 @@ Note that some events cannot be tagged with a Transaction ID: ### Reference, Topic and Correlator by Event Type -| Types | Reference | Topic | Correlator | -|---------------------------------------------|--------------------------------------|-----------------------------|-------------------------| +| Types | Reference | Topic | Correlator | +|---------------------------------------------|-------------------------------------------|-----------------------------|-------------------------| | `transaction_submitted` | [Transaction](./transaction.html) | `transaction.type` | | | `message_confirmed`
`message_rejected` | [Message](./message.html) | `message.header.topics[i]`* | `message.header.cid` | | `token_pool_confirmed` | [TokenPool](./tokenpool.html) | `tokenPool.id` | | @@ -90,6 +90,8 @@ Note that some events cannot be tagged with a Transaction ID: | `blockchain_event_received` | [BlockchainEvent](./blockchainevent.html) | From listener ** | | | `blockchain_invoke_op_succeeded` | [Operation](./operation.html) | | | | `blockchain_invoke_op_failed` | [Operation](./operation.html) | | | +| `blockchain_contract_deploy_op_succeeded` | [Operation](./operation.html) | | | +| `blockchain_contract_deploy_op_failed` | [Operation](./operation.html) | | | > * A separate event is emitted for _each topic_ associated with a [Message](./message.html). diff --git a/internal/blockchain/ethereum/ethereum.go b/internal/blockchain/ethereum/ethereum.go index 5ccf8716de..62292c9f01 100644 --- a/internal/blockchain/ethereum/ethereum.go +++ b/internal/blockchain/ethereum/ethereum.go @@ -56,7 +56,6 @@ type Ethereum struct { capabilities *blockchain.Capabilities callbacks common.BlockchainCallbacks client *resty.Client - fftmClient *resty.Client streams *streamManager streamID string wsconn wsclient.WSClient @@ -132,7 +131,6 @@ func (e *Ethereum) Init(ctx context.Context, cancelCtx context.CancelFunc, conf e.InitConfig(conf) ethconnectConf := e.ethconnectConf addressResolverConf := conf.SubSection(AddressResolverConfigKey) - fftmConf := conf.SubSection(FFTMConfigKey) e.ctx = log.WithLogField(ctx, "proto", "ethereum") e.cancelCtx = cancelCtx @@ -152,10 +150,6 @@ func (e *Ethereum) Init(ctx context.Context, cancelCtx context.CancelFunc, conf } e.client = ffresty.New(e.ctx, ethconnectConf) - if fftmConf.GetString(ffresty.HTTPConfigURL) != "" { - e.fftmClient = ffresty.New(e.ctx, fftmConf) - } - e.topic = ethconnectConf.GetString(EthconnectConfigTopic) if e.topic == "" { return i18n.NewError(ctx, coremsgs.MsgMissingPluginConfig, "topic", "blockchain.ethereum.ethconnect") @@ -569,12 +563,8 @@ func (e *Ethereum) invokeContractMethod(ctx context.Context, address, signingKey if err != nil { return err } - client := e.fftmClient - if client == nil { - client = e.client - } var resErr ethError - res, err := client.R(). + res, err := e.client.R(). SetContext(ctx). SetBody(body). SetError(&resErr). @@ -706,17 +696,18 @@ func (e *Ethereum) DeployContract(ctx context.Context, nsOpID, signingKey string return err } - client := e.fftmClient - if client == nil { - client = e.client - } var resErr ethError - res, err := client.R(). + res, err := e.client.R(). SetContext(ctx). SetBody(body). SetError(&resErr). Post("/") if err != nil || !res.IsSuccess() { + if strings.Contains(string(res.Body()), "FFEC100130") { + // This error is returned by ethconnect because it does not support deploying contracts with this syntax + // Return a more helpful and clear error message + return i18n.NewError(ctx, coremsgs.MsgNotSupportedByBlockchainPlugin) + } return wrapError(ctx, &resErr, res, err) } return nil From 4f650ca17422bf2ce129a8faf3052117a404a712 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 8 Nov 2022 11:30:28 -0500 Subject: [PATCH 2/2] Fix ethereum unit tests Signed-off-by: Nicko Guyer --- internal/blockchain/ethereum/ethereum_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/blockchain/ethereum/ethereum_test.go b/internal/blockchain/ethereum/ethereum_test.go index d7e2655624..0c205f344d 100644 --- a/internal/blockchain/ethereum/ethereum_test.go +++ b/internal/blockchain/ethereum/ethereum_test.go @@ -196,7 +196,6 @@ func TestInitAndStartWithEthConnect(t *testing.T) { cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) err := e.Init(e.ctx, e.cancelCtx, utConfig, e.metrics, cmi) assert.NoError(t, err) - assert.NotNil(t, e.fftmClient) assert.Equal(t, "ethereum", e.Name()) assert.Equal(t, core.VerifierTypeEthAddress, e.VerifierType()) @@ -258,7 +257,6 @@ func TestInitAndStartWithFFTM(t *testing.T) { cmi.On("GetCache", mock.Anything).Return(cache.NewUmanagedCache(e.ctx, 100, 5*time.Minute), nil) err := e.Init(e.ctx, e.cancelCtx, utConfig, e.metrics, cmi) assert.NoError(t, err) - assert.NotNil(t, e.fftmClient) assert.Equal(t, "ethereum", e.Name()) assert.Equal(t, core.VerifierTypeEthAddress, e.VerifierType())