-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6264 from AndriiDiachuk/add-rest-endpoint-GetAcco…
…untKeys [Access] Add REST endpoint to get an accounts public keys
- Loading branch information
Showing
10 changed files
with
415 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Access API | ||
* | ||
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) | ||
*/ | ||
package models | ||
|
||
type AccountPublicKeys struct { | ||
Keys []AccountPublicKey `json:"keys"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
type GetAccountKeys struct { | ||
Address flow.Address | ||
Height uint64 | ||
} | ||
|
||
func (g *GetAccountKeys) Build(r *Request) error { | ||
return g.Parse( | ||
r.GetVar(addressVar), | ||
r.GetQueryParam(blockHeightQuery), | ||
r.Chain, | ||
) | ||
} | ||
|
||
func (g *GetAccountKeys) Parse( | ||
rawAddress string, | ||
rawHeight string, | ||
chain flow.Chain, | ||
) error { | ||
address, err := ParseAddress(rawAddress, chain) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var height Height | ||
err = height.Parse(rawHeight) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.Address = address | ||
g.Height = height.Flow() | ||
|
||
// default to last block | ||
if g.Height == EmptyHeight { | ||
g.Height = SealedHeight | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package request | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
func Test_GetAccountKeys_InvalidParse(t *testing.T) { | ||
var getAccountKeys GetAccountKeys | ||
|
||
tests := []struct { | ||
address string | ||
height string | ||
err string | ||
}{ | ||
{"", "", "invalid address"}, | ||
{"f8d6e0586b0a20c7", "-1", "invalid height format"}, | ||
} | ||
|
||
chain := flow.Localnet.Chain() | ||
for i, test := range tests { | ||
err := getAccountKeys.Parse(test.address, test.height, chain) | ||
assert.EqualError(t, err, test.err, fmt.Sprintf("test #%d failed", i)) | ||
} | ||
} | ||
|
||
func Test_GetAccountKeys_ValidParse(t *testing.T) { | ||
var getAccountKeys GetAccountKeys | ||
|
||
addr := "f8d6e0586b0a20c7" | ||
chain := flow.Localnet.Chain() | ||
err := getAccountKeys.Parse(addr, "", chain) | ||
assert.NoError(t, err) | ||
assert.Equal(t, getAccountKeys.Address.String(), addr) | ||
assert.Equal(t, getAccountKeys.Height, SealedHeight) | ||
|
||
err = getAccountKeys.Parse(addr, "100", chain) | ||
assert.NoError(t, err) | ||
assert.Equal(t, getAccountKeys.Height, uint64(100)) | ||
|
||
err = getAccountKeys.Parse(addr, sealed, chain) | ||
assert.NoError(t, err) | ||
assert.Equal(t, getAccountKeys.Height, SealedHeight) | ||
|
||
err = getAccountKeys.Parse(addr, final, chain) | ||
assert.NoError(t, err) | ||
assert.Equal(t, getAccountKeys.Height, FinalHeight) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.