Skip to content

Commit

Permalink
chore: fix stake response encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Dec 10, 2024
1 parent 9b9a03e commit b35bd1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions p2p/pkg/rpc/provider/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,15 @@ func (s *Service) Stake(
}

for i, _ := range stake.BlsPublicKeys {
tx, txErr = s.registryContract.AddVerifiedBLSKey(opts, []byte(stake.BlsPublicKeys[i]), []byte(stake.BlsSignatures[i]))
blsPublicKey, err := hex.DecodeString(strings.TrimPrefix(stake.BlsPublicKeys[i], "0x"))
if err != nil {
return nil, status.Errorf(codes.Internal, "decoding bls public key: %v", err)
}
blsSignature, err := hex.DecodeString(strings.TrimPrefix(stake.BlsSignatures[i], "0x"))
if err != nil {
return nil, status.Errorf(codes.Internal, "decoding bls signature: %v", err)
}
tx, txErr = s.registryContract.AddVerifiedBLSKey(opts, blsPublicKey, blsSignature)
if txErr != nil {
return nil, status.Errorf(codes.Internal, "adding verified bls key: %v", txErr)
}
Expand All @@ -288,7 +296,7 @@ func (s *Service) Stake(
for _, log := range receipt.Logs {
if blsKeyEvent, err := s.registryContract.ParseBLSKeyAdded(*log); err == nil {
s.logger.Info("verified bls key added", "key", blsKeyEvent.BlsPublicKey)
stakeResponse.BlsPublicKeys = append(stakeResponse.BlsPublicKeys, string(blsKeyEvent.BlsPublicKey))
stakeResponse.BlsPublicKeys = append(stakeResponse.BlsPublicKeys, hex.EncodeToString(blsKeyEvent.BlsPublicKey))
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions p2p/pkg/rpc/provider/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
)

type testRegistryContract struct {
stake *big.Int
topup *big.Int
minStake *big.Int
blsKey []byte
stake *big.Int
topup *big.Int
minStake *big.Int
blsKey []byte
blsSignature []byte
}

func (t *testRegistryContract) ProviderRegistered(opts *bind.CallOpts, address common.Address) (bool, error) {
Expand All @@ -50,6 +51,7 @@ func (t *testRegistryContract) RegisterAndStake(opts *bind.TransactOpts) (*types

func (t *testRegistryContract) AddVerifiedBLSKey(opts *bind.TransactOpts, blsPublicKey []byte, blsSignature []byte) (*types.Transaction, error) {
t.blsKey = blsPublicKey
t.blsSignature = blsSignature
return types.NewTransaction(1, common.Address{}, nil, 0, nil, nil), nil
}

Expand Down

0 comments on commit b35bd1f

Please sign in to comment.