Skip to content

Commit 15e89dd

Browse files
authored
feat(framework): add Aptos key readers to clclient (#2492)
* feat(framework): add aptos key readers * fix(framework): avoid aptos key warning on request errors
1 parent 1e8de4c commit 15e89dd

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

framework/.changeset/v0.15.10.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Expose Aptos key and account readers in the Chainlink REST client

framework/clclient/client.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,46 @@ func (c *ChainlinkClient) ReadTxKeys(chain string) (*TxKeys, *http.Response, err
857857
return txKeys, resp.RawResponse, err
858858
}
859859

860+
// ReadAptosKeys reads all Aptos keys from the Chainlink node
861+
func (c *ChainlinkClient) ReadAptosKeys() (*AptosKeys, *resty.Response, error) {
862+
aptosKeys := &AptosKeys{}
863+
framework.L.Info().Str(NodeURL, c.Config.URL).Msg("Reading Aptos Keys")
864+
resp, err := c.APIClient.R().
865+
SetResult(aptosKeys).
866+
Get("/v2/keys/aptos")
867+
if err != nil {
868+
return nil, nil, err
869+
}
870+
if len(aptosKeys.Data) == 0 {
871+
framework.L.Warn().Str(NodeURL, c.Config.URL).Msg("Found no Aptos Keys on the node")
872+
}
873+
return aptosKeys, resp, nil
874+
}
875+
876+
// MustReadAptosKeys reads all Aptos keys from the Chainlink node and returns an error if the request is unsuccessful.
877+
func (c *ChainlinkClient) MustReadAptosKeys() (*AptosKeys, *resty.Response, error) {
878+
aptosKeys, res, err := c.ReadAptosKeys()
879+
if err != nil {
880+
return nil, res, err
881+
}
882+
return aptosKeys, res, VerifyStatusCodeWithResponse(res, http.StatusOK)
883+
}
884+
885+
// MustReadAptosAccounts reads all Aptos account addresses from the Chainlink node.
886+
func (c *ChainlinkClient) MustReadAptosAccounts() ([]string, error) {
887+
aptosKeys, _, err := c.MustReadAptosKeys()
888+
if err != nil {
889+
return nil, err
890+
}
891+
892+
accounts := make([]string, 0, len(aptosKeys.Data))
893+
for _, key := range aptosKeys.Data {
894+
accounts = append(accounts, key.Attributes.Account)
895+
}
896+
897+
return accounts, nil
898+
}
899+
860900
// DeleteTxKey deletes an tx key based on the provided ID
861901
func (c *ChainlinkClient) DeleteTxKey(chain string, id string) (*http.Response, error) {
862902
framework.L.Info().Str(NodeURL, c.Config.URL).Str("ID", id).Msg("Deleting Tx Key")

framework/clclient/models.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ type WorkflowKeys struct {
228228
Data []WorkflowKey `json:"data"`
229229
}
230230

231+
// AptosKeyAttributes is the model that represents the created Aptos key attributes when read
232+
type AptosKeyAttributes struct {
233+
Account string `json:"account"`
234+
PublicKey string `json:"publicKey"`
235+
}
236+
237+
// AptosKeyData is the model that represents the created Aptos keys when read
238+
type AptosKeyData struct {
239+
ID string `json:"id"`
240+
Attributes AptosKeyAttributes `json:"attributes"`
241+
}
242+
243+
// AptosKey is the model that represents the created Aptos key when read
244+
type AptosKey struct {
245+
Data AptosKeyData `json:"data"`
246+
}
247+
248+
// AptosKeys is the model that represents the created Aptos keys when read
249+
type AptosKeys struct {
250+
Data []AptosKeyData `json:"data"`
251+
}
252+
231253
// OCRKeys is the model that represents the created OCR keys when read
232254
type OCRKeys struct {
233255
Data []OCRKeyData `json:"data"`

0 commit comments

Comments
 (0)