Skip to content

Commit 9bb30dc

Browse files
authored
Merge pull request #65 from flow-hydraulics/latenssi/api-update-2
API update, refactor transaction error handling
2 parents 3f07046 + 4c604bd commit 9bb30dc

23 files changed

Lines changed: 195 additions & 184 deletions

api/misc.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ POST http://localhost:3000/v1/distributions HTTP/1.1
55
content-type: application/json
66

77
{
8-
"distId": 1,
8+
"distFlowID": 1,
99
"issuer":"0x1",
1010
"meta": {
1111
"title": "Test",

benchmarkcreate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ func benchmarkCreate(packs, slots uint, b *testing.B) {
2323
collection := makeTestCollection(int(packs * slots))
2424

2525
dReq := pds_http.ReqCreateDistribution{
26-
DistID: common.FlowID{Int64: int64(1), Valid: true},
26+
FlowID: common.FlowID{Int64: int64(1), Valid: true},
2727
Issuer: addr,
28-
PackTemplate: pds_http.PackTemplate{
28+
PackTemplate: pds_http.ReqPackTemplate{
2929
PackReference: pds_http.AddressLocation{
3030
Name: "TestPackNFT",
3131
Address: addr,
3232
},
3333
PackCount: packs,
34-
Buckets: []pds_http.Bucket{
34+
Buckets: []pds_http.ReqBucket{
3535
{
3636
CollectibleReference: pds_http.AddressLocation{
3737
Name: "TestCollectibleNFT",

e2e_large_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func TestE2ELarge(t *testing.T) {
185185
}
186186

187187
distribution := app.Distribution{
188-
DistID: distId,
188+
FlowID: distId,
189189
Issuer: issuer,
190190
PackTemplate: app.PackTemplate{
191191
PackReference: app.AddressLocation{
@@ -222,7 +222,7 @@ func TestE2ELarge(t *testing.T) {
222222
t.Log("Wait for the distribution to complete")
223223

224224
for {
225-
d, _, err := a.GetDistribution(context.Background(), distribution.ID)
225+
d, err := a.GetDistribution(context.Background(), distribution.ID)
226226
if err != nil {
227227
if !strings.Contains(err.Error(), "database is locked") {
228228
t.Fatal(err)

e2e_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestE2E(t *testing.T) {
172172
}
173173

174174
distribution := app.Distribution{
175-
DistID: distId,
175+
FlowID: distId,
176176
Issuer: issuer,
177177
PackTemplate: app.PackTemplate{
178178
PackReference: app.AddressLocation{
@@ -209,7 +209,7 @@ func TestE2E(t *testing.T) {
209209
t.Log("Wait for the distribution to complete")
210210

211211
for {
212-
d, _, err := a.GetDistribution(context.Background(), distribution.ID)
212+
d, err := a.GetDistribution(context.Background(), distribution.ID)
213213
if err != nil {
214214
t.Fatal(err)
215215
}

main_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ func TestCreate(t *testing.T) {
3030
collection := makeTestCollection(packs * slotsPerBucket)
3131

3232
dReq := pds_http.ReqCreateDistribution{
33-
DistID: common.FlowID{Int64: int64(1), Valid: true},
33+
FlowID: common.FlowID{Int64: int64(1), Valid: true},
3434
Issuer: addr,
35-
PackTemplate: pds_http.PackTemplate{
35+
PackTemplate: pds_http.ReqPackTemplate{
3636
PackReference: pds_http.AddressLocation{
3737
Name: "TestPackNFT",
3838
Address: addr,
3939
},
4040
PackCount: uint(packs),
41-
Buckets: []pds_http.Bucket{
41+
Buckets: []pds_http.ReqBucket{
4242
{
4343
CollectibleReference: pds_http.AddressLocation{
4444
Name: "TestCollectibleNFT",
@@ -79,13 +79,13 @@ func TestCreate(t *testing.T) {
7979
t.Fatal(err)
8080
}
8181

82-
AssertNotEqual(t, createRes.DistributionId, uuid.Nil)
82+
AssertNotEqual(t, createRes.ID, uuid.Nil)
8383

8484
// Get
8585

8686
rr2 := httptest.NewRecorder()
8787

88-
getReq, err := http.NewRequest("GET", fmt.Sprintf("/v1/distributions/%s", createRes.DistributionId), nil)
88+
getReq, err := http.NewRequest("GET", fmt.Sprintf("/v1/distributions/%s", createRes.ID), nil)
8989
if err != nil {
9090
t.Fatal(err)
9191
}
@@ -97,14 +97,11 @@ func TestCreate(t *testing.T) {
9797
t.Fatalf("handler returned wrong status code: got %v want %v, error: %s", status, http.StatusOK, rr2.Body)
9898
}
9999

100-
getRes := pds_http.ResDistribution{}
100+
getRes := pds_http.ResGetDistribution{}
101101
if err := json.NewDecoder(rr2.Body).Decode(&getRes); err != nil {
102102
t.Fatal(err)
103103
}
104104

105-
AssertEqual(t, getRes.ID, createRes.DistributionId)
105+
AssertEqual(t, getRes.ID, createRes.ID)
106106
AssertEqual(t, getRes.Issuer, addr)
107-
AssertEqual(t, len(getRes.ResolvedCollection), len(collection))
108-
AssertEqual(t, len(getRes.Packs), packs)
109-
AssertEqual(t, getRes.Packs[0].CommitmentHash.IsEmpty(), false)
110107
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ properties:
1313
$ref: ./Contract-Reference.yaml
1414
collectibleCount:
1515
type: integer
16-
format: int64
1716
minimum: 1
17+
example: 4
1818
collectibleCollection:
1919
type: array
2020
uniqueItems: true
2121
minItems: 1
2222
items:
2323
type: integer
24-
format: int64
2524
minimum: 1
25+
example: 42
26+
required:
27+
- collectibleReference
28+
- collectibleCount
29+
- collectibleCollection

models/Bucket-Get.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
type: object
2+
title: Bucket
3+
description: ''
4+
examples:
5+
- collectibleCount: 1
6+
collectibleCollection:
7+
- 1
8+
- 2
9+
- 3
10+
- 4
11+
properties:
12+
collectibleReference:
13+
$ref: ./Contract-Reference.yaml
14+
collectibleCount:
15+
type: integer
16+
minimum: 1
17+
example: 4

models/Contract-Reference.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description: Way of referencing a contract on Flow.
44
properties:
55
name:
66
type: string
7+
example: ExampleNFT
78
address:
89
$ref: ./Flow-Address.yaml
910
required:
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
title: Distribution
22
type: object
3+
description: ''
34
properties:
4-
id:
5+
distID:
56
type: string
7+
format: uuid
8+
distFlowID:
9+
type: integer
10+
minimum: 0
11+
example: 1
612
createdAt:
713
type: string
814
format: date-time
915
updatedAt:
1016
type: string
1117
format: date-time
12-
distId:
13-
type: integer
14-
format: int64
15-
minimum: 0
16-
example: 1
1718
issuer:
1819
$ref: ./Flow-Address.yaml
1920
state:
@@ -27,15 +28,4 @@ properties:
2728
meta:
2829
$ref: ./Distribution-Meta.yaml
2930
packTemplate:
30-
$ref: ./Pack-Template.yaml
31-
packs:
32-
type: array
33-
items:
34-
$ref: ./Pack.yaml
35-
resolvedCollection:
36-
type: array
37-
items:
38-
type: string
39-
example: A.0000000000000003.CollectibleNFT.11
40-
settlementStatus:
41-
$ref: ./Settlement-Status.yaml
31+
$ref: ./Pack-Template-Get.yaml
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
title: Distribution List Item
22
type: object
33
properties:
4-
id:
4+
distID:
55
type: string
6+
format: uuid
7+
distFlowID:
8+
type: integer
9+
minimum: 0
10+
example: 1
611
createdAt:
712
type: string
813
format: date-time
914
updatedAt:
1015
type: string
1116
format: date-time
12-
distId:
13-
type: integer
14-
format: int64
15-
minimum: 0
16-
example: 1
1717
issuer:
1818
$ref: ./Flow-Address.yaml
1919
state:

0 commit comments

Comments
 (0)