-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get signature endpoint: alternative PR with different packaging (#507)
* base warp backend * add signature caching * add docs * error handling * pr fixes * basic signature request * hash unsigned message for key * implement new Request and RequestHandler interfaces * signature handler impl without constructing one * fix import * quick pr fixes and merge * quick pr fixes and merge * save signature instead of whole msg * use avaGO cache * rename warpBackend and docs * fix nits * Update plugin/evm/warp_backend.go Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com> * Update plugin/evm/warp_backend.go Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com> * fix pr nits * pr fixes and testing * type check for caching * handlers and request before tests * fix imports * signature handler with stats and test * use memdb and remove extra test * remove unused * fix imports * fix imports * nit * update license year * use require noError * saving message in db and pr fixes * create noop signature handler and refactor code handler * get signature endpoint * add api arg to evm client * Update sync/handlers/handler.go Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com> * update backend return value * refactor handlers to network handler * change constructor of handler stats * pr cleanups * warp api * initialize warp backend * build fix * wip * warp api follows eth api pattern * cleanup and comments * clean up response * fix warp client return type * nits for get-signature-endpoint (#502) Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org> Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com> Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org> Co-authored-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com> * resolve merge conflict * warp: Group packages for symmetry w/ sync * more reshuffle * more shuffle * pr comments * fix * update to []byte * update svc return type * rename arg * fix type * add stats pkg --------- Co-authored-by: Matthew Lam <matthew.lam@avalabs.org> Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com> Co-authored-by: cam-schultz <camschultz32@gmail.com> Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org> Co-authored-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com>
- Loading branch information
1 parent
8343e42
commit 38ad7f5
Showing
12 changed files
with
118 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
handlers/warp/signature_request.go → warp/handlers/signature_request.go
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
File renamed without changes.
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 @@ | ||
// (c) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package warp | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/subnet-evm/rpc" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
) | ||
|
||
var _ WarpClient = (*warpClient)(nil) | ||
|
||
type WarpClient interface { | ||
GetSignature(ctx context.Context, messageID ids.ID) ([]byte, error) | ||
} | ||
|
||
// warpClient implementation for interacting with EVM [chain] | ||
type warpClient struct { | ||
client *rpc.Client | ||
} | ||
|
||
// NewWarpClient returns a WarpClient for interacting with EVM [chain] | ||
func NewWarpClient(uri, chain string) (WarpClient, error) { | ||
client, err := rpc.Dial(fmt.Sprintf("%s/ext/bc/%s/rpc", uri, chain)) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to dial client. err: %w", err) | ||
} | ||
return &warpClient{ | ||
client: client, | ||
}, nil | ||
} | ||
|
||
// GetSignature requests the BLS signature associated with a messageID | ||
func (c *warpClient) GetSignature(ctx context.Context, messageID ids.ID) ([]byte, error) { | ||
var res hexutil.Bytes | ||
err := c.client.CallContext(ctx, &res, "warp_getSignature", messageID) | ||
if err != nil { | ||
return nil, fmt.Errorf("call to warp_getSignature failed. err: %w", err) | ||
} | ||
return res, err | ||
} |
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,26 @@ | ||
// (c) 2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package warp | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
) | ||
|
||
// WarpAPI introduces snowman specific functionality to the evm | ||
type WarpAPI struct { | ||
Backend WarpBackend | ||
} | ||
|
||
// GetSignature returns the BLS signature associated with a messageID. | ||
func (api *WarpAPI) GetSignature(ctx context.Context, messageID ids.ID) (hexutil.Bytes, error) { | ||
signature, err := api.Backend.GetSignature(ctx, messageID) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get signature for with error %w", err) | ||
} | ||
return signature[:], nil | ||
} |