Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions foundation/rpc_server/asset_converter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rpc

import (
"fmt"

"github.com/pkg/errors"
"github.com/qubic/go-node-connector/types"
"github.com/qubic/qubic-http/protobuff"
Expand Down Expand Up @@ -78,3 +80,30 @@ func convertAssetPossession(source types.AssetPossession) (*protobuff.AssetPosse

return &assetPossession, nil
}

func convertContractIpo(source types.ContractIpo) (*protobuff.IpoBidData, error) {

ipoBidData := protobuff.IpoBidData{
ContractIndex: source.ContractIndex,
TickNumber: source.TickNumber,
Bids: make(map[int32]*protobuff.IpoBid),
}

for index := 0; index < types.NumberOfComputors; index++ {
if source.Prices[index] == 0 {
continue
}

identity, err := new(types.Identity).FromPubKey(source.PubKeys[index], false)
if err != nil {
return nil, fmt.Errorf("failed to get identity for bid: %w", err)
}

ipoBidData.Bids[int32(index)] = &protobuff.IpoBid{
Identity: identity.String(),
Amount: source.Prices[index],
}
}

return &ipoBidData, nil
}
46 changes: 46 additions & 0 deletions foundation/rpc_server/asset_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,49 @@ func TestAssetConverter_convertAssetPossession(t *testing.T) {
}, converted)

}

func TestAssetConverter_convertContractIpo(t *testing.T) {

id := types.Identity("TESTIOGXQKYYZEQXOXFSWWAJNYLCDBWFAPNBLNBUZFHDVFMYPJZXGMEEJEGI")
pubKey, err := id.ToPubKey(false)
assert.NoError(t, err)

source := types.ContractIpo{
ContractIndex: 5,
TickNumber: 100,
}

// set one bid with a known identity and price
source.PubKeys[0] = pubKey
source.Prices[0] = 1000

// set another bid at a different index
source.PubKeys[10] = pubKey
source.Prices[10] = 2000

// index 1 has zero price, should be skipped
source.PubKeys[1] = pubKey
source.Prices[1] = 0

converted, err := convertContractIpo(source)
assert.NoError(t, err)

assert.Equal(t, uint32(5), converted.ContractIndex)
assert.Equal(t, uint32(100), converted.TickNumber)

// only 2 bids should be present (zero-price skipped)
assert.Len(t, converted.Bids, 2)

assert.Equal(t, &protobuff.IpoBid{
Identity: "TESTIOGXQKYYZEQXOXFSWWAJNYLCDBWFAPNBLNBUZFHDVFMYPJZXGMEEJEGI",
Amount: 1000,
}, converted.Bids[0])

assert.Equal(t, &protobuff.IpoBid{
Identity: "TESTIOGXQKYYZEQXOXFSWWAJNYLCDBWFAPNBLNBUZFHDVFMYPJZXGMEEJEGI",
Amount: 2000,
}, converted.Bids[10])

// zero-price bid should not be in the map
assert.Nil(t, converted.Bids[1])
}
22 changes: 22 additions & 0 deletions foundation/rpc_server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,28 @@ func (s *Server) GetActiveIpos(ctx context.Context, _ *emptypb.Empty) (*protobuf
return &protobuff.GetActiveIposResponse{Ipos: ipos}, nil
}

func (s *Server) GetContractIpoBids(ctx context.Context, request *protobuff.GetContractIpoBidsRequest) (*protobuff.GetContractIpoBidsResponse, error) {

client, err := s.qPool.Get()
if err != nil {
return nil, status.Errorf(codes.Internal, "getting connection from pool: %v", err)
}

nodeResponse, err := client.GetContractIpo(ctx, request.ContractIndex)
if err != nil {
s.qPool.Close(client)
return nil, status.Errorf(codes.Internal, "getting contract ipo data: %v", err)
}
s.qPool.Put(client)

ipoBidData, err := convertContractIpo(nodeResponse)
if err != nil {
return nil, status.Errorf(codes.Internal, "converting node response: %v", err)
}

return &protobuff.GetContractIpoBidsResponse{BidData: ipoBidData}, nil
}

func (s *Server) Start() error {
srv := grpc.NewServer(
grpc.MaxRecvMsgSize(600*1024*1024),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/gnostic v0.7.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3
github.com/pkg/errors v0.9.1
github.com/qubic/go-node-connector v0.15.0
github.com/qubic/go-node-connector v0.17.0
github.com/qubic/go-schnorrq v1.0.1
github.com/stretchr/testify v1.11.1
google.golang.org/genproto/googleapis/api v0.0.0-20251103181224-f26f9409b101
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qubic/go-node-connector v0.15.0 h1:fbd+wgEBtKMzmlsRdbYAKAGnDxew4HLjAPj4whGKWjY=
github.com/qubic/go-node-connector v0.15.0/go.mod h1:GOQGJ6IKhm3CU62bfLJJbBerjYmt6NNhDKzxC1i7HhU=
github.com/qubic/go-node-connector v0.17.0 h1:ifsqODfO3vw16av0GGQBcq8qgcQXfYD1Y4/xIvlasx8=
github.com/qubic/go-node-connector v0.17.0/go.mod h1:GOQGJ6IKhm3CU62bfLJJbBerjYmt6NNhDKzxC1i7HhU=
github.com/qubic/go-schnorrq v1.0.1 h1:F0R/BQVf+O7Bp57NGJmc3uXlqsaIzerg/1bmU4jMLLE=
github.com/qubic/go-schnorrq v1.0.1/go.mod h1:j2qw/zHiyjH9GAScAAETWpZk6iELbjYnzIg7CQwc5wM=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
Expand Down
Loading