github.com/cgcardona/r-subnet-evm@v0.1.5/warp/warp_client_fetcher.go (about) 1 // (c) 2023, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package warp 5 6 import ( 7 "context" 8 "fmt" 9 10 "github.com/ava-labs/avalanchego/ids" 11 "github.com/ava-labs/avalanchego/utils/crypto/bls" 12 avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" 13 ) 14 15 type warpAPIFetcher struct { 16 clients map[ids.NodeID]WarpClient 17 } 18 19 func NewWarpAPIFetcher(clients map[ids.NodeID]WarpClient) *warpAPIFetcher { 20 return &warpAPIFetcher{ 21 clients: clients, 22 } 23 } 24 25 func (f *warpAPIFetcher) FetchWarpSignature(ctx context.Context, nodeID ids.NodeID, unsignedWarpMessage *avalancheWarp.UnsignedMessage) (*bls.Signature, error) { 26 client, ok := f.clients[nodeID] 27 if !ok { 28 return nil, fmt.Errorf("no warp client for nodeID: %s", nodeID) 29 } 30 31 signatureBytes, err := client.GetSignature(ctx, unsignedWarpMessage.ID()) 32 if err != nil { 33 return nil, err 34 } 35 36 signature, err := bls.SignatureFromBytes(signatureBytes) 37 if err != nil { 38 return nil, fmt.Errorf("failed to parse signature from client %s: %w", nodeID, err) 39 } 40 return signature, nil 41 }