Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
b90e92cd
Unverified
Commit
b90e92cd
authored
Jul 15, 2021
by
mrekucci
Committed by
GitHub
Jul 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add expired field to the postage stamp response (#2328)
parent
4909a7f5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
5 deletions
+59
-5
SwarmCommon.yaml
openapi/SwarmCommon.yaml
+2
-0
postage.go
pkg/debugapi/postage.go
+20
-3
postage_test.go
pkg/debugapi/postage_test.go
+2
-0
store.go
pkg/postage/batchstore/mock/store.go
+10
-1
store.go
pkg/postage/batchstore/store.go
+12
-0
interface.go
pkg/postage/interface.go
+2
-1
service.go
pkg/postage/mock/service.go
+5
-0
service.go
pkg/postage/service.go
+6
-0
No files found.
openapi/SwarmCommon.yaml
View file @
b90e92cd
...
...
@@ -333,6 +333,8 @@ components:
type
:
integer
immutableFlag
:
type
:
boolean
exists
:
type
:
boolean
Settlement
:
type
:
object
...
...
pkg/debugapi/postage.go
View file @
b90e92cd
...
...
@@ -101,6 +101,7 @@ type postageStampResponse struct {
BucketDepth
uint8
`json:"bucketDepth"`
BlockNumber
uint64
`json:"blockNumber"`
ImmutableFlag
bool
`json:"immutableFlag"`
Exists
bool
`json:"exists"`
}
type
postageStampsResponse
struct
{
...
...
@@ -110,6 +111,13 @@ type postageStampsResponse struct {
func
(
s
*
Service
)
postageGetStampsHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
resp
:=
postageStampsResponse
{}
for
_
,
v
:=
range
s
.
post
.
StampIssuers
()
{
exists
,
err
:=
s
.
post
.
BatchExists
(
v
.
ID
())
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"get stamp issuer: check batch: %v"
,
err
)
s
.
logger
.
Error
(
"get stamp issuer: check batch"
)
jsonhttp
.
InternalServerError
(
w
,
"unable to check batch"
)
return
}
resp
.
Stamps
=
append
(
resp
.
Stamps
,
postageStampResponse
{
BatchID
:
v
.
ID
(),
Utilization
:
v
.
Utilization
(),
...
...
@@ -120,6 +128,7 @@ func (s *Service) postageGetStampsHandler(w http.ResponseWriter, _ *http.Request
BucketDepth
:
v
.
BucketDepth
(),
BlockNumber
:
v
.
BlockNumber
(),
ImmutableFlag
:
v
.
ImmutableFlag
(),
Exists
:
exists
,
})
}
jsonhttp
.
OK
(
w
,
resp
)
...
...
@@ -127,14 +136,14 @@ func (s *Service) postageGetStampsHandler(w http.ResponseWriter, _ *http.Request
func
(
s
*
Service
)
postageGetStampHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
idStr
:=
mux
.
Vars
(
r
)[
"id"
]
if
idStr
==
""
||
len
(
idStr
)
!=
64
{
if
len
(
idStr
)
!=
64
{
s
.
logger
.
Error
(
"get stamp issuer: invalid batchID"
)
jsonhttp
.
BadRequest
(
w
,
"invalid batchID"
)
return
}
id
,
err
:=
hex
.
DecodeString
(
idStr
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"get stamp issuer: invalid batchID: %v"
,
err
)
s
.
logger
.
Error
f
(
"get stamp issuer: invalid batchID: %v"
,
err
)
s
.
logger
.
Error
(
"get stamp issuer: invalid batchID"
)
jsonhttp
.
BadRequest
(
w
,
"invalid batchID"
)
return
...
...
@@ -142,11 +151,18 @@ func (s *Service) postageGetStampHandler(w http.ResponseWriter, r *http.Request)
issuer
,
err
:=
s
.
post
.
GetStampIssuer
(
id
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"get stamp issuer: get issuer: %v"
,
err
)
s
.
logger
.
Error
f
(
"get stamp issuer: get issuer: %v"
,
err
)
s
.
logger
.
Error
(
"get stamp issuer: get issuer"
)
jsonhttp
.
BadRequest
(
w
,
"cannot get issuer"
)
return
}
exists
,
err
:=
s
.
post
.
BatchExists
(
id
)
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"get stamp issuer: check batch: %v"
,
err
)
s
.
logger
.
Error
(
"get stamp issuer: check batch"
)
jsonhttp
.
InternalServerError
(
w
,
"unable to check batch"
)
return
}
resp
:=
postageStampResponse
{
BatchID
:
id
,
Utilization
:
issuer
.
Utilization
(),
...
...
@@ -157,6 +173,7 @@ func (s *Service) postageGetStampHandler(w http.ResponseWriter, r *http.Request)
BucketDepth
:
issuer
.
BucketDepth
(),
BlockNumber
:
issuer
.
BlockNumber
(),
ImmutableFlag
:
issuer
.
ImmutableFlag
(),
Exists
:
exists
,
}
jsonhttp
.
OK
(
w
,
&
resp
)
}
...
...
pkg/debugapi/postage_test.go
View file @
b90e92cd
...
...
@@ -211,6 +211,7 @@ func TestPostageGetStamps(t *testing.T) {
BucketDepth
:
si
.
BucketDepth
(),
BlockNumber
:
si
.
BlockNumber
(),
ImmutableFlag
:
si
.
ImmutableFlag
(),
Exists
:
true
,
},
},
}),
...
...
@@ -234,6 +235,7 @@ func TestPostageGetStamp(t *testing.T) {
BucketDepth
:
si
.
BucketDepth
(),
BlockNumber
:
si
.
BlockNumber
(),
ImmutableFlag
:
si
.
ImmutableFlag
(),
Exists
:
true
,
}),
)
})
...
...
pkg/postage/batchstore/mock/store.go
View file @
b90e92cd
...
...
@@ -92,7 +92,11 @@ func (bs *BatchStore) Get(id []byte) (*postage.Batch, error) {
}
bs
.
getErrDelayCnt
--
}
if
!
bytes
.
Equal
(
bs
.
id
,
id
)
{
exists
,
err
:=
bs
.
Exists
(
id
)
if
err
!=
nil
{
return
nil
,
err
}
if
!
exists
{
return
nil
,
errors
.
New
(
"no such id"
)
}
return
bs
.
batch
,
nil
...
...
@@ -147,6 +151,11 @@ func (bs *BatchStore) SetRadiusSetter(r postage.RadiusSetter) {
panic
(
"not implemented"
)
}
// Exists reports whether batch referenced by the give id exists.
func
(
bs
*
BatchStore
)
Exists
(
id
[]
byte
)
(
bool
,
error
)
{
return
bytes
.
Equal
(
bs
.
id
,
id
),
nil
}
func
(
bs
*
BatchStore
)
Reset
()
error
{
bs
.
resetCallCount
++
return
nil
...
...
pkg/postage/batchstore/store.go
View file @
b90e92cd
...
...
@@ -198,6 +198,18 @@ func (s *store) SetRadiusSetter(r postage.RadiusSetter) {
s
.
radiusSetter
=
r
}
// Exists reports whether batch referenced by the give id exists.
func
(
s
*
store
)
Exists
(
id
[]
byte
)
(
bool
,
error
)
{
switch
err
:=
s
.
store
.
Get
(
batchKey
(
id
),
new
(
postage
.
Batch
));
{
case
err
==
nil
:
return
true
,
nil
case
errors
.
Is
(
err
,
storage
.
ErrNotFound
)
:
return
false
,
nil
default
:
return
false
,
err
}
}
func
(
s
*
store
)
Reset
()
error
{
prefix
:=
"batchstore_"
if
err
:=
s
.
store
.
Iterate
(
prefix
,
func
(
k
,
_
[]
byte
)
(
bool
,
error
)
{
...
...
pkg/postage/interface.go
View file @
b90e92cd
...
...
@@ -30,11 +30,12 @@ type UnreserveIteratorFn func(id []byte, radius uint8) (bool, error)
type
Storer
interface
{
Get
(
id
[]
byte
)
(
*
Batch
,
error
)
Put
(
*
Batch
,
*
big
.
Int
,
uint8
)
error
PutChainState
(
*
ChainState
)
error
GetChainState
()
*
ChainState
PutChainState
(
*
ChainState
)
error
GetReserveState
()
*
ReserveState
SetRadiusSetter
(
RadiusSetter
)
Unreserve
(
UnreserveIteratorFn
)
error
Exists
(
id
[]
byte
)
(
bool
,
error
)
Reset
()
error
}
...
...
pkg/postage/mock/service.go
View file @
b90e92cd
...
...
@@ -69,6 +69,11 @@ func (m *mockPostage) IssuerUsable(_ *postage.StampIssuer) bool {
return
true
}
// BatchExists returns always true.
func
(
m
*
mockPostage
)
BatchExists
(
_
[]
byte
)
(
bool
,
error
)
{
return
true
,
nil
}
func
(
m
*
mockPostage
)
Handle
(
_
*
postage
.
Batch
)
{}
func
(
m
*
mockPostage
)
Close
()
error
{
...
...
pkg/postage/service.go
View file @
b90e92cd
...
...
@@ -34,6 +34,7 @@ type Service interface {
StampIssuers
()
[]
*
StampIssuer
GetStampIssuer
([]
byte
)
(
*
StampIssuer
,
error
)
IssuerUsable
(
*
StampIssuer
)
bool
BatchExists
([]
byte
)
(
bool
,
error
)
BatchCreationListener
io
.
Closer
}
...
...
@@ -123,6 +124,11 @@ func (ps *service) IssuerUsable(st *StampIssuer) bool {
return
true
}
// BatchExists returns true if the batch referenced by the given id exists.
func
(
ps
*
service
)
BatchExists
(
id
[]
byte
)
(
bool
,
error
)
{
return
ps
.
postageStore
.
Exists
(
id
)
}
// GetStampIssuer finds a stamp issuer by batch ID.
func
(
ps
*
service
)
GetStampIssuer
(
batchID
[]
byte
)
(
*
StampIssuer
,
error
)
{
ps
.
lock
.
Lock
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment