Skip to content

Commit f9f12b1

Browse files
committed
Reformat ipo-service into general-service and implement balances for multiple identities request.
1 parent badfa45 commit f9f12b1

48 files changed

Lines changed: 2000 additions & 1116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/push-docker-ipo-service.yaml renamed to .github/workflows/push-docker-general-service.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
name: Deploy ipo-service image to GHCR
1+
name: Deploy general-service image to GHCR
22

33
on:
44
push:
55
tags:
6-
- 'ipo-service/v*.*.*'
6+
- 'general-service/v*.*.*'
77

88
jobs:
99
test:
1010
runs-on: ubuntu-latest
1111
defaults:
1212
run:
13-
working-directory: ./ipo-service
13+
working-directory: ./general-service
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
1717

1818
- name: Set up Go
1919
uses: actions/setup-go@v5
2020
with:
21-
go-version-file: ipo-service/go.mod
21+
go-version-file: general-service/go.mod
2222

2323
- name: Run tests
2424
run: go test ./...
@@ -55,7 +55,7 @@ jobs:
5555
- name: Build and push Docker image
5656
uses: docker/build-push-action@v5
5757
with:
58-
context: ./ipo-service
59-
file: ./ipo-service/Dockerfile
58+
context: ./general-service
59+
file: ./general-service/Dockerfile
6060
push: true
61-
tags: ghcr.io/qubic/qubic-aggregation-ipo-service:${{ steps.extract.outputs.version }}
61+
tags: ghcr.io/qubic/qubic-aggregation-general-service:${{ steps.extract.outputs.version }}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Test general-service
2+
3+
on:
4+
push:
5+
paths:
6+
- 'general-service/**'
7+
- 'shared/**'
8+
pull_request:
9+
paths:
10+
- 'general-service/**'
11+
- 'shared/**'
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: ./general-service
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: general-service/go.mod
27+
28+
- name: Run tests
29+
run: go test ./...

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ exposes the results via its own gRPC + HTTP/REST API.
66

77
## Services
88

9-
| Service | Description | Status |
10-
|-----------------------------|----------------------------------------------------------------|-------------|
11-
| [ipo-service](ipo-service/) | IPO bid aggregation for wallet integration | Implemented |
12-
| [shared](shared/) | Common infrastructure (gRPC client/server, config, middleware) | Implemented |
9+
| Service | Description | Status |
10+
|---------------------------------------|----------------------------------------------------------------|-------------|
11+
| [general-service](general-service/) | IPO bid aggregation and identity balances | Implemented |
12+
| [shared](shared/) | Common infrastructure (gRPC client/server, config, middleware) | Implemented |
1313

1414
## Architecture
1515

@@ -18,9 +18,9 @@ exposes the results via its own gRPC + HTTP/REST API.
1818
|
1919
+------------v------------+
2020
| Aggregation Layer |
21-
| +-------------------+ |
22-
| | ipo-service | |
23-
| +--------+----------+ |
21+
| +---------------------+ |
22+
| | general-service | |
23+
| +--------+-----------+ |
2424
| | |
2525
| +--------v----------+ |
2626
| | shared module | |

buf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: v2
22
modules:
3-
- path: ipo-service/api
3+
- path: general-service/api
44
deps:
55
- buf.build/googleapis/googleapis
66
- buf.build/grpc-ecosystem/grpc-gateway

general-service/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.26 AS builder
2+
ENV CGO_ENABLED=0
3+
4+
WORKDIR /src
5+
COPY . /src
6+
7+
RUN go build -o "./bin/general-service" "./cmd/general-service"
8+
9+
FROM alpine
10+
COPY --from=builder /src/bin/general-service /app/general-service
11+
12+
EXPOSE 8000
13+
EXPOSE 8001
14+
EXPOSE 9999
15+
16+
WORKDIR /app
17+
18+
ENTRYPOINT ["./general-service"]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
proto-gen:
44
buf generate
5-
mv api/openapi.yaml api/ipo-service.openapi.yaml
5+
mv api/openapi.yaml api/general-service.openapi.yaml
66

7-
PROTO_GEN_DIR = api/qubic/aggregation/ipo/v1
7+
PROTO_GEN_DIR = api/qubic/aggregation/general/v1
88

99
proto-clean:
10-
rm -f $(PROTO_GEN_DIR)/*.pb.go $(PROTO_GEN_DIR)/*.pb.gw.go api/ipo-service.openapi.yaml
10+
rm -f $(PROTO_GEN_DIR)/*.pb.go $(PROTO_GEN_DIR)/*.pb.gw.go api/general-service.openapi.yaml
1111

1212
proto-lint:
1313
buf lint
Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# IPO Service
1+
# General Service
22

3-
Aggregates IPO bid transaction data. Given a set of bidder identities, returns their bid transactions for all currently active IPOs with parsed bid data (price, quantity).
3+
General-purpose aggregation service. Currently provides IPO bid transaction aggregation and batch identity balance lookups.
44

55
## API
66

77
### `GetCurrentIpoBids`
88

9-
**gRPC**: `qubic.aggregation.ipo.v1.AggregationIpoService/GetCurrentIpoBids`
9+
**gRPC**: `qubic.aggregation.general.v1.AggregationGeneralService/GetCurrentIpoBids`
1010
**HTTP**: `POST /getCurrentIpoBids`
1111

1212
**Request**: up to 15 identity strings.
@@ -46,27 +46,68 @@ Aggregates IPO bid transaction data. Given a set of bidder identities, returns t
4646
}
4747
```
4848

49+
### `GetIdentitiesBalances`
50+
51+
**gRPC**: `qubic.aggregation.general.v1.AggregationGeneralService/GetIdentitiesBalances`
52+
**HTTP**: `POST /getIdentitiesBalances`
53+
54+
**Request**: up to 15 identity strings.
55+
56+
```json
57+
{
58+
"identities": ["IDENTITY_A", "IDENTITY_B"]
59+
}
60+
```
61+
62+
**Response**: balance data for each identity.
63+
64+
```json
65+
{
66+
"balances": [
67+
{
68+
"id": "IDENTITY_A",
69+
"balance": 1000000,
70+
"valid_for_tick": 22150100,
71+
"latest_incoming_transfer_tick": 22150090,
72+
"latest_outgoing_transfer_tick": 22150080,
73+
"incoming_amount": 5000000,
74+
"outgoing_amount": 4000000,
75+
"number_of_incoming_transfers": 10,
76+
"number_of_outgoing_transfers": 5
77+
}
78+
]
79+
}
80+
```
81+
4982
## How It Works
5083

84+
### IPO Bids
85+
5186
1. Fetches active IPO contract indices from qubic-http (`GetActiveIpos`), cached with configurable TTL.
5287
2. Derives smart contract addresses from contract indices (contract index in lower 32 bits of the 256-bit public key, remaining bits zeroed).
5388
3. Gets current epoch tick bounds from status-service (`GetTickIntervals`), cached with configurable TTL.
5489
4. For each identity, queries archive-query-service (`GetTransactionsForIdentity`) with destination = SC address, tick range = current epoch, amount = 0.
5590
5. Filters results by `input_size == 10` and `amount == 0` to isolate IPO bid transactions.
5691
6. Parses `input_data` (base64) as `ContractIPOBid`: price (int64 LE, 8 bytes) + quantity (uint16 LE, 2 bytes).
5792

93+
### Identity Balances
94+
95+
1. For each identity, concurrently fetches the balance from qubic-http (`GetBalance`).
96+
2. Returns all balance fields (current balance, transfer ticks, amounts, transfer counts).
97+
5898
## Upstream Dependencies
5999

60100
| Service | Method | Purpose |
61101
|---------|--------|---------|
62102
| qubic-http | `GetActiveIpos` | Active IPO contract indices |
63103
| qubic-http | `GetTickInfo` | Current epoch for tick range |
104+
| qubic-http | `GetBalance` | Identity balance data |
64105
| status-service | `GetTickIntervals` | Epoch tick boundaries |
65106
| archive-query-service | `GetTransactionsForIdentity` | Bid transaction queries |
66107

67108
## Configuration
68109

69-
Environment variable prefix: `QUBIC_AGGREGATION_IPO_SERVICE`
110+
Environment variable prefix: `QUBIC_AGGREGATION_GENERAL_SERVICE`
70111

71112
| Variable | Default | Description |
72113
|----------|---------|-------------|
@@ -92,19 +133,19 @@ make mocks
92133
make test
93134

94135
# Build
95-
go build ./cmd/ipo-service
136+
go build ./cmd/general-service
96137

97138
# Build Docker image
98-
docker build -t ipo-service .
139+
docker build -t general-service .
99140
```
100141

101142
## Project Structure
102143

103144
```
104-
ipo-service/
105-
cmd/ipo-service/ Entry point, config, bootstrap
106-
api/ Proto definitions + generated gRPC/gateway code
107-
domain/ Business logic, interfaces, models
108-
grpc/ gRPC service handler + server setup
109-
clients/ Upstream service client wrappers
145+
general-service/
146+
cmd/general-service/ Entry point, config, bootstrap
147+
api/ Proto definitions + generated gRPC/gateway code
148+
domain/ Business logic, interfaces, models
149+
grpc/ gRPC service handler + server setup
150+
clients/ Upstream service client wrappers
110151
```

ipo-service/api/ipo-service.openapi.yaml renamed to general-service/api/general-service.openapi.yaml

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
openapi: 3.0.3
55
info:
6-
title: Qubic IPO Aggregation Service
7-
description: API for querying transactions related to smart contract IPO bids.
6+
title: Qubic General Aggregation Service
7+
description: General API for aggregated data / requests.
88
version: 1.0.0
99
servers:
1010
- url: https://TO-DEFINE
1111
paths:
1212
/getCurrentIpoBids:
1313
post:
1414
tags:
15-
- AggregationIpoService
15+
- AggregationGeneralService
1616
summary: Get bidder bid transactions for currently active IPOs.
1717
description: Allows for requesting the transactions associated with bids of currently active IPOs for a number of bidder identities.
18-
operationId: AggregationIpoService_GetCurrentIpoBids
18+
operationId: AggregationGeneralService_GetCurrentIpoBids
1919
requestBody:
2020
content:
2121
application/json:
@@ -29,6 +29,26 @@ paths:
2929
application/json:
3030
schema:
3131
$ref: '#/components/schemas/GetCurrentIpoBidsResponse'
32+
/getIdentitiesBalances:
33+
post:
34+
tags:
35+
- AggregationGeneralService
36+
summary: Get balances for a list of identities.
37+
description: Allows for requesting the balances for a number of Qubic wallet identities.
38+
operationId: AggregationGeneralService_GetIdentitiesBalances
39+
requestBody:
40+
content:
41+
application/json:
42+
schema:
43+
$ref: '#/components/schemas/GetIdentitiesBalancesRequest'
44+
required: true
45+
responses:
46+
"200":
47+
description: OK
48+
content:
49+
application/json:
50+
schema:
51+
$ref: '#/components/schemas/GetIdentitiesBalancesResponse'
3252
components:
3353
schemas:
3454
BidTransaction:
@@ -75,6 +95,46 @@ components:
7595
type: array
7696
items:
7797
$ref: '#/components/schemas/IpoBidTransactions'
98+
GetIdentitiesBalancesRequest:
99+
type: object
100+
properties:
101+
identities:
102+
type: array
103+
items:
104+
type: string
105+
GetIdentitiesBalancesResponse:
106+
type: object
107+
properties:
108+
balances:
109+
type: array
110+
items:
111+
$ref: '#/components/schemas/IdentityBalance'
112+
IdentityBalance:
113+
type: object
114+
properties:
115+
id:
116+
type: string
117+
balance:
118+
type: string
119+
validForTick:
120+
type: integer
121+
format: uint32
122+
latestIncomingTransferTick:
123+
type: integer
124+
format: uint32
125+
latestOutgoingTransferTick:
126+
type: integer
127+
format: uint32
128+
incomingAmount:
129+
type: string
130+
outgoingAmount:
131+
type: string
132+
numberOfIncomingTransfers:
133+
type: integer
134+
format: uint32
135+
numberOfOutgoingTransfers:
136+
type: integer
137+
format: uint32
78138
IpoBid:
79139
type: object
80140
properties:
@@ -98,7 +158,7 @@ components:
98158
items:
99159
$ref: '#/components/schemas/BidTransaction'
100160
tags:
101-
- name: AggregationIpoService
161+
- name: AggregationGeneralService
102162
externalDocs:
103163
description: GitHub
104164
url: https://github.com/qubic/qubic-aggregation

0 commit comments

Comments
 (0)