diff --git a/chain/tee.go b/chain/tee.go index 223a64b..6c6f408 100755 --- a/chain/tee.go +++ b/chain/tee.go @@ -43,11 +43,13 @@ func (c *chainClient) QueryTeeWorkerMap(puk []byte) (pattern.TeeWorkerInfo, erro key, err := types.CreateStorageKey(c.metadata, pattern.TEEWORKER, pattern.TEEWORKERMAP, owner) if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] CreateStorageKey: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEWORKERMAP, err) return data, errors.Wrap(err, "[CreateStorageKey]") } ok, err := c.api.RPC.State.GetStorageLatest(key, &data) if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEWORKERMAP, err) return data, errors.Wrap(err, "[GetStorageLatest]") } if !ok { @@ -108,11 +110,13 @@ func (c *chainClient) QueryTeePodr2Puk() ([]byte, error) { key, err := types.CreateStorageKey(c.metadata, pattern.TEEWORKER, pattern.TEEPODR2PK) if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] CreateStorageKey: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEPODR2PK, err) return nil, errors.Wrap(err, "[CreateStorageKey]") } ok, err := c.api.RPC.State.GetStorageLatest(key, &data) if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEPODR2PK, err) return nil, errors.Wrap(err, "[GetStorageLatest]") } if !ok { @@ -138,11 +142,13 @@ func (c *chainClient) QueryAllTeeWorkerMap() ([]pattern.TeeWorkerInfo, error) { key := createPrefixedKey(pattern.TEEWORKER, pattern.TEEWORKERMAP) keys, err := c.api.RPC.State.GetKeysLatest(key) if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetKeysLatest: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEWORKERMAP, err) return list, errors.Wrap(err, "[GetKeysLatest]") } set, err := c.api.RPC.State.QueryStorageAtLatest(keys) if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] QueryStorageAtLatest: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEWORKERMAP, err) return list, errors.Wrap(err, "[QueryStorageAtLatest]") } @@ -150,7 +156,7 @@ func (c *chainClient) QueryAllTeeWorkerMap() ([]pattern.TeeWorkerInfo, error) { for _, change := range elem.Changes { var teeWorker pattern.TeeWorkerInfo if err := codec.Decode(change.StorageData, &teeWorker); err != nil { - fmt.Println(err) + log.Println(err) continue } list = append(list, teeWorker) @@ -189,3 +195,34 @@ func (c *chainClient) QueryAllTeeInfo() ([]pattern.TeeInfo, error) { } return results, nil } + +func (c *chainClient) QueryTeeWorkEndpoint() (string, error) { + defer func() { + if err := recover(); err != nil { + log.Println(utils.RecoverError(err)) + } + }() + + var data types.Text + + if !c.GetChainState() { + return "", pattern.ERR_RPC_CONNECTION + } + + key, err := types.CreateStorageKey(c.metadata, pattern.TEEWORKER, pattern.TEEEndpoints) + if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] CreateStorageKey: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEEndpoints, err) + return "", errors.Wrap(err, "[CreateStorageKey]") + } + + ok, err := c.api.RPC.State.GetStorageLatest(key, &data) + if err != nil { + err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetStorageLatest: %v", c.GetCurrentRpcAddr(), pattern.TEEWORKER, pattern.TEEEndpoints, err) + return "", errors.Wrap(err, "[GetStorageLatest]") + } + if !ok { + return "", pattern.ERR_RPC_EMPTY_VALUE + } + + return string(data), nil +} diff --git a/core/event/events.go b/core/event/events.go index 49e3102..4e74689 100755 --- a/core/event/events.go +++ b/core/event/events.go @@ -321,19 +321,6 @@ type Event_LeaseExpireIn24Hours struct { } // ------------------------TEE Worker-------------------- -type Event_RegistrationTeeWorker struct { - Phase types.Phase - Acc types.AccountID - PeerId pattern.PeerId - Topics []types.Hash -} - -type Event_UpdatePeerId struct { - Phase types.Phase - Acc types.AccountID - Topics []types.Hash -} - type Event_Exit struct { Phase types.Phase Acc types.AccountID @@ -517,12 +504,9 @@ type EventRecords struct { StorageHandler_LeaseExpireIn24Hours []Event_LeaseExpireIn24Hours // TeeWorker - TeeWorker_RegistrationTeeWorker []Event_RegistrationTeeWorker - TeeWorker_UpdatePeerId []Event_UpdatePeerId - TeeWorker_Exit []Event_Exit - TeeWorker_MasterKeyLaunched []Event_MasterKeyLaunched - TeeWorker_KeyfairyAdded []Event_KeyfairyAdded - + TeeWorker_Exit []Event_Exit + TeeWorker_MasterKeyLaunched []Event_MasterKeyLaunched + TeeWorker_KeyfairyAdded []Event_KeyfairyAdded TeeWorker_WorkerUpdated []Event_WorkerUpdated TeeWorker_MasterKeyRotated []Event_MasterKeyRotated TeeWorker_MasterKeyRotationFailed []Event_MasterKeyRotationFailed diff --git a/core/event/eventsName.go b/core/event/eventsName.go index a1c8285..9718743 100755 --- a/core/event/eventsName.go +++ b/core/event/eventsName.go @@ -64,8 +64,6 @@ const ( StorageHandlerRenewalSpace = "StorageHandler.RenewalSpace" // TeeWorker - TeeWorkerRegistrationTeeWorker = "TeeWorker.RegistrationTeeWorker" - TeeWorkerUpdatePeerId = "TeeWorker.UpdatePeerId" TeeWorkerExit = "TeeWorker.Exit" TeeWorkerMasterKeyLaunched = "TeeWorker.MasterKeyLaunched" TeeWorkerKeyfairyAdded = "TeeWorker.KeyfairyAdded" diff --git a/core/pattern/pattern.go b/core/pattern/pattern.go index b0f1b90..2201e49 100755 --- a/core/pattern/pattern.go +++ b/core/pattern/pattern.go @@ -77,6 +77,7 @@ const ( // TEEWORKER TEEWORKERMAP = "TeeWorkerMap" TEEPODR2PK = "TeePodr2Pk" + TEEEndpoints = "Endpoints" // FILEBANK FILE = "File" diff --git a/core/sdk/sdk.go b/core/sdk/sdk.go index 4291ae9..708280f 100755 --- a/core/sdk/sdk.go +++ b/core/sdk/sdk.go @@ -213,6 +213,8 @@ type SDK interface { QueryAllTeeWorkerMap() ([]pattern.TeeWorkerInfo, error) // QueryAllTeeInfo queries the information of all tee workers. QueryAllTeeInfo() ([]pattern.TeeInfo, error) + // QueryTeeWorkEndpoint queries the endpoint of tee workers. + QueryTeeWorkEndpoint() (string, error) // System