Skip to content

Commit

Permalink
Merge pull request #1476 from onflow/chasefleming/1474
Browse files Browse the repository at this point in the history
Support previewnet for `accounts create`
  • Loading branch information
chasefleming authored Mar 29, 2024
2 parents 881846c + 96511d1 commit 65f033f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/accounts/create-interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ func (l *lilicoAccount) create(network string) (flowsdk.Identifier, error) {
apiNetwork = "/testnet"
}

if network == config.PreviewnetNetwork.Name {
apiNetwork = "/previewnet"
}

request, err := http.NewRequest(
http.MethodPost,
fmt.Sprintf("https://openapi.lilico.org/v1/address%s", apiNetwork),
Expand All @@ -259,6 +263,7 @@ func (l *lilicoAccount) create(network string) (flowsdk.Identifier, error) {
request.Header.Add("Authorization", accountToken)

client := &http.Client{
Timeout: time.Second * 20,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // lilico api doesn't yet have a valid cert, todo reevaluate
},
Expand All @@ -269,6 +274,11 @@ func (l *lilicoAccount) create(network string) (flowsdk.Identifier, error) {
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(res.Body)
return flowsdk.EmptyID, fmt.Errorf("account creation failed with status %d: %s", res.StatusCode, string(bodyBytes))
}

body, _ := io.ReadAll(res.Body)
var lilicoRes lilicoResponse

Expand Down

0 comments on commit 65f033f

Please sign in to comment.