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
7383d3dc
Unverified
Commit
7383d3dc
authored
Jun 09, 2021
by
Adam Uhlíř
Committed by
GitHub
Jun 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: marshal bigint as string (#1735)
parent
e1025971
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
227 additions
and
106 deletions
+227
-106
SwarmCommon.yaml
openapi/SwarmCommon.yaml
+14
-9
bigint.go
pkg/bigint/bigint.go
+44
-0
bigint_test.go
pkg/bigint/bigint_test.go
+28
-0
balances.go
pkg/debugapi/balances.go
+7
-7
balances_test.go
pkg/debugapi/balances_test.go
+9
-8
chequebook.go
pkg/debugapi/chequebook.go
+17
-16
chequebook_test.go
pkg/debugapi/chequebook_test.go
+17
-16
export_test.go
pkg/debugapi/export_test.go
+2
-0
postage.go
pkg/debugapi/postage.go
+29
-2
postage_test.go
pkg/debugapi/postage_test.go
+14
-4
settlements.go
pkg/debugapi/settlements.go
+20
-19
settlements_test.go
pkg/debugapi/settlements_test.go
+19
-18
chainstate.go
pkg/postage/chainstate.go
+3
-3
reservestate.go
pkg/postage/reservestate.go
+4
-4
No files found.
openapi/SwarmCommon.yaml
View file @
7383d3dc
...
@@ -34,6 +34,11 @@ components:
...
@@ -34,6 +34,11 @@ components:
pssPublicKey
:
pssPublicKey
:
$ref
:
"
#/components/schemas/PublicKey"
$ref
:
"
#/components/schemas/PublicKey"
BigInt
:
description
:
Numeric string that represents integer which might exceeds `Number.MAX_SAFE_INTEGER` limit (2^53-1)
type
:
string
example
:
"
1000000000000000000"
ReserveState
:
ReserveState
:
type
:
object
type
:
object
properties
:
properties
:
...
@@ -42,9 +47,9 @@ components:
...
@@ -42,9 +47,9 @@ components:
available
:
available
:
type
:
integer
type
:
integer
outer
:
outer
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
inner
:
inner
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
ChainState
:
ChainState
:
type
:
object
type
:
object
...
@@ -62,7 +67,7 @@ components:
...
@@ -62,7 +67,7 @@ components:
peer
:
peer
:
$ref
:
"
#/components/schemas/SwarmAddress"
$ref
:
"
#/components/schemas/SwarmAddress"
balance
:
balance
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
Balances
:
Balances
:
type
:
object
type
:
object
...
@@ -109,7 +114,7 @@ components:
...
@@ -109,7 +114,7 @@ components:
chequebook
:
chequebook
:
$ref
:
"
#/components/schemas/EthereumAddress"
$ref
:
"
#/components/schemas/EthereumAddress"
payout
:
payout
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
ChequeAllPeersResponse
:
ChequeAllPeersResponse
:
type
:
object
type
:
object
...
@@ -134,9 +139,9 @@ components:
...
@@ -134,9 +139,9 @@ components:
type
:
object
type
:
object
properties
:
properties
:
totalBalance
:
totalBalance
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
availableBalance
:
availableBalance
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
ChequebookAddress
:
ChequebookAddress
:
type
:
object
type
:
object
...
@@ -159,7 +164,7 @@ components:
...
@@ -159,7 +164,7 @@ components:
type
:
string
type
:
string
pattern
:
"
^[A-Fa-f0-9]{40}$"
pattern
:
"
^[A-Fa-f0-9]{40}$"
example
:
"
36b7efd913ca4cf880b8eeac5093fa27b0825906"
example
:
"
36b7efd913ca4cf880b8eeac5093fa27b0825906"
FileName
:
FileName
:
type
:
string
type
:
string
...
@@ -388,7 +393,7 @@ components:
...
@@ -388,7 +393,7 @@ components:
recipient
:
recipient
:
$ref
:
"
#/components/schemas/EthereumAddress"
$ref
:
"
#/components/schemas/EthereumAddress"
lastPayout
:
lastPayout
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
bounced
:
bounced
:
type
:
boolean
type
:
boolean
...
@@ -404,7 +409,7 @@ components:
...
@@ -404,7 +409,7 @@ components:
result
:
result
:
$ref
:
"
#/components/schemas/SwapCashoutResult"
$ref
:
"
#/components/schemas/SwapCashoutResult"
uncashedAmount
:
uncashedAmount
:
type
:
integer
$ref
:
"
#/components/schemas/BigInt"
TagName
:
TagName
:
type
:
string
type
:
string
...
...
pkg/bigint/bigint.go
0 → 100644
View file @
7383d3dc
// Copyright 2021 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
bigint
import
(
"encoding/json"
"fmt"
"math/big"
)
type
BigInt
struct
{
*
big
.
Int
}
func
(
i
*
BigInt
)
MarshalJSON
()
([]
byte
,
error
)
{
if
i
.
Int
==
nil
{
return
[]
byte
(
"null"
),
nil
}
return
[]
byte
(
fmt
.
Sprintf
(
`"%s"`
,
i
.
String
())),
nil
}
func
(
i
*
BigInt
)
UnmarshalJSON
(
b
[]
byte
)
error
{
var
val
string
err
:=
json
.
Unmarshal
(
b
,
&
val
)
if
err
!=
nil
{
return
err
}
if
i
.
Int
==
nil
{
i
.
Int
=
new
(
big
.
Int
)
}
i
.
SetString
(
val
,
10
)
return
nil
}
//Wrap wraps big.Int pointer into BigInt struct.
func
Wrap
(
i
*
big
.
Int
)
*
BigInt
{
return
&
BigInt
{
Int
:
i
}
}
pkg/bigint/bigint_test.go
0 → 100644
View file @
7383d3dc
// Copyright 2021 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
bigint_test
import
(
"encoding/json"
"github.com/ethersphere/bee/pkg/bigint"
"math"
"math/big"
"reflect"
"testing"
)
func
TestMarshaling
(
t
*
testing
.
T
)
{
mar
,
err
:=
json
.
Marshal
(
struct
{
Bg
*
bigint
.
BigInt
}{
Bg
:
bigint
.
Wrap
(
new
(
big
.
Int
)
.
Mul
(
big
.
NewInt
(
math
.
MaxInt64
),
big
.
NewInt
(
math
.
MaxInt64
))),
})
if
err
!=
nil
{
t
.
Errorf
(
"Marshaling failed: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
mar
,
[]
byte
(
"{
\"
Bg
\"
:
\"
85070591730234615847396907784232501249
\"
}"
))
{
t
.
Errorf
(
"Wrongly marshaled data"
)
}
}
pkg/debugapi/balances.go
View file @
7383d3dc
...
@@ -6,10 +6,10 @@ package debugapi
...
@@ -6,10 +6,10 @@ package debugapi
import
(
import
(
"errors"
"errors"
"math/big"
"net/http"
"net/http"
"github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
...
@@ -23,8 +23,8 @@ var (
...
@@ -23,8 +23,8 @@ var (
)
)
type
balanceResponse
struct
{
type
balanceResponse
struct
{
Peer
string
`json:"peer"`
Peer
string
`json:"peer"`
Balance
*
big
.
Int
`json:"balance"`
Balance
*
big
int
.
Big
Int
`json:"balance"`
}
}
type
balancesResponse
struct
{
type
balancesResponse
struct
{
...
@@ -45,7 +45,7 @@ func (s *Service) balancesHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -45,7 +45,7 @@ func (s *Service) balancesHandler(w http.ResponseWriter, r *http.Request) {
for
k
:=
range
balances
{
for
k
:=
range
balances
{
balResponses
[
i
]
=
balanceResponse
{
balResponses
[
i
]
=
balanceResponse
{
Peer
:
k
,
Peer
:
k
,
Balance
:
b
alances
[
k
]
,
Balance
:
b
igint
.
Wrap
(
balances
[
k
])
,
}
}
i
++
i
++
}
}
...
@@ -77,7 +77,7 @@ func (s *Service) peerBalanceHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -77,7 +77,7 @@ func (s *Service) peerBalanceHandler(w http.ResponseWriter, r *http.Request) {
jsonhttp
.
OK
(
w
,
balanceResponse
{
jsonhttp
.
OK
(
w
,
balanceResponse
{
Peer
:
peer
.
String
(),
Peer
:
peer
.
String
(),
Balance
:
b
alance
,
Balance
:
b
igint
.
Wrap
(
balance
)
,
})
})
}
}
...
@@ -95,7 +95,7 @@ func (s *Service) compensatedBalancesHandler(w http.ResponseWriter, r *http.Requ
...
@@ -95,7 +95,7 @@ func (s *Service) compensatedBalancesHandler(w http.ResponseWriter, r *http.Requ
for
k
:=
range
balances
{
for
k
:=
range
balances
{
balResponses
[
i
]
=
balanceResponse
{
balResponses
[
i
]
=
balanceResponse
{
Peer
:
k
,
Peer
:
k
,
Balance
:
b
alances
[
k
]
,
Balance
:
b
igint
.
Wrap
(
balances
[
k
])
,
}
}
i
++
i
++
}
}
...
@@ -127,6 +127,6 @@ func (s *Service) compensatedPeerBalanceHandler(w http.ResponseWriter, r *http.R
...
@@ -127,6 +127,6 @@ func (s *Service) compensatedPeerBalanceHandler(w http.ResponseWriter, r *http.R
jsonhttp
.
OK
(
w
,
balanceResponse
{
jsonhttp
.
OK
(
w
,
balanceResponse
{
Peer
:
peer
.
String
(),
Peer
:
peer
.
String
(),
Balance
:
b
alance
,
Balance
:
b
igint
.
Wrap
(
balance
)
,
})
})
}
}
pkg/debugapi/balances_test.go
View file @
7383d3dc
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/accounting/mock"
"github.com/ethersphere/bee/pkg/accounting/mock"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
...
@@ -35,15 +36,15 @@ func TestBalances(t *testing.T) {
...
@@ -35,15 +36,15 @@ func TestBalances(t *testing.T) {
[]
debugapi
.
BalanceResponse
{
[]
debugapi
.
BalanceResponse
{
{
{
Peer
:
"DEAD"
,
Peer
:
"DEAD"
,
Balance
:
big
.
NewInt
(
1000000000000000000
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
1000000000000000000
)
),
},
},
{
{
Peer
:
"BEEF"
,
Peer
:
"BEEF"
,
Balance
:
big
.
NewInt
(
-
100000000000000000
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
-
100000000000000000
)
),
},
},
{
{
Peer
:
"PARTY"
,
Peer
:
"PARTY"
,
Balance
:
big
.
NewInt
(
0
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
},
},
},
},
}
}
...
@@ -89,7 +90,7 @@ func TestBalancesPeers(t *testing.T) {
...
@@ -89,7 +90,7 @@ func TestBalancesPeers(t *testing.T) {
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/balances/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/balances/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
BalanceResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
BalanceResponse
{
Peer
:
peer
,
Peer
:
peer
,
Balance
:
big
.
NewInt
(
100000000000000000
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
100000000000000000
)
),
}),
}),
)
)
}
}
...
@@ -188,15 +189,15 @@ func TestConsumedBalances(t *testing.T) {
...
@@ -188,15 +189,15 @@ func TestConsumedBalances(t *testing.T) {
[]
debugapi
.
BalanceResponse
{
[]
debugapi
.
BalanceResponse
{
{
{
Peer
:
"DEAD"
,
Peer
:
"DEAD"
,
Balance
:
big
.
NewInt
(
1000000000000000000
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
1000000000000000000
)
),
},
},
{
{
Peer
:
"BEEF"
,
Peer
:
"BEEF"
,
Balance
:
big
.
NewInt
(
-
100000000000000000
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
-
100000000000000000
)
),
},
},
{
{
Peer
:
"PARTY"
,
Peer
:
"PARTY"
,
Balance
:
big
.
NewInt
(
0
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
},
},
},
},
}
}
...
@@ -242,7 +243,7 @@ func TestConsumedPeers(t *testing.T) {
...
@@ -242,7 +243,7 @@ func TestConsumedPeers(t *testing.T) {
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/consumed/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/consumed/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
BalanceResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
BalanceResponse
{
Peer
:
peer
,
Peer
:
peer
,
Balance
:
big
.
NewInt
(
1000000000000000000
),
Balance
:
big
int
.
Wrap
(
big
.
NewInt
(
1000000000000000000
)
),
}),
}),
)
)
}
}
...
...
pkg/debugapi/chequebook.go
View file @
7383d3dc
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"strconv"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/settlement/swap/chequebook"
"github.com/ethersphere/bee/pkg/settlement/swap/chequebook"
...
@@ -39,8 +40,8 @@ var (
...
@@ -39,8 +40,8 @@ var (
)
)
type
chequebookBalanceResponse
struct
{
type
chequebookBalanceResponse
struct
{
TotalBalance
*
big
.
Int
`json:"totalBalance"`
TotalBalance
*
big
int
.
Big
Int
`json:"totalBalance"`
AvailableBalance
*
big
.
Int
`json:"availableBalance"`
AvailableBalance
*
big
int
.
Big
Int
`json:"availableBalance"`
}
}
type
chequebookAddressResponse
struct
{
type
chequebookAddressResponse
struct
{
...
@@ -48,9 +49,9 @@ type chequebookAddressResponse struct {
...
@@ -48,9 +49,9 @@ type chequebookAddressResponse struct {
}
}
type
chequebookLastChequePeerResponse
struct
{
type
chequebookLastChequePeerResponse
struct
{
Beneficiary
string
`json:"beneficiary"`
Beneficiary
string
`json:"beneficiary"`
Chequebook
string
`json:"chequebook"`
Chequebook
string
`json:"chequebook"`
Payout
*
big
.
Int
`json:"payout"`
Payout
*
big
int
.
Big
Int
`json:"payout"`
}
}
type
chequebookLastChequesPeerResponse
struct
{
type
chequebookLastChequesPeerResponse
struct
{
...
@@ -80,7 +81,7 @@ func (s *Service) chequebookBalanceHandler(w http.ResponseWriter, r *http.Reques
...
@@ -80,7 +81,7 @@ func (s *Service) chequebookBalanceHandler(w http.ResponseWriter, r *http.Reques
return
return
}
}
jsonhttp
.
OK
(
w
,
chequebookBalanceResponse
{
TotalBalance
:
b
alance
,
AvailableBalance
:
availableBalance
})
jsonhttp
.
OK
(
w
,
chequebookBalanceResponse
{
TotalBalance
:
b
igint
.
Wrap
(
balance
),
AvailableBalance
:
bigint
.
Wrap
(
availableBalance
)
})
}
}
func
(
s
*
Service
)
chequebookAddressHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
s
*
Service
)
chequebookAddressHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -110,7 +111,7 @@ func (s *Service) chequebookLastPeerHandler(w http.ResponseWriter, r *http.Reque
...
@@ -110,7 +111,7 @@ func (s *Service) chequebookLastPeerHandler(w http.ResponseWriter, r *http.Reque
lastSentResponse
=
&
chequebookLastChequePeerResponse
{
lastSentResponse
=
&
chequebookLastChequePeerResponse
{
Beneficiary
:
lastSent
.
Cheque
.
Beneficiary
.
String
(),
Beneficiary
:
lastSent
.
Cheque
.
Beneficiary
.
String
(),
Chequebook
:
lastSent
.
Cheque
.
Chequebook
.
String
(),
Chequebook
:
lastSent
.
Cheque
.
Chequebook
.
String
(),
Payout
:
lastSent
.
Cheque
.
CumulativePayout
,
Payout
:
bigint
.
Wrap
(
lastSent
.
Cheque
.
CumulativePayout
)
,
}
}
}
}
...
@@ -126,7 +127,7 @@ func (s *Service) chequebookLastPeerHandler(w http.ResponseWriter, r *http.Reque
...
@@ -126,7 +127,7 @@ func (s *Service) chequebookLastPeerHandler(w http.ResponseWriter, r *http.Reque
lastReceivedResponse
=
&
chequebookLastChequePeerResponse
{
lastReceivedResponse
=
&
chequebookLastChequePeerResponse
{
Beneficiary
:
lastReceived
.
Cheque
.
Beneficiary
.
String
(),
Beneficiary
:
lastReceived
.
Cheque
.
Beneficiary
.
String
(),
Chequebook
:
lastReceived
.
Cheque
.
Chequebook
.
String
(),
Chequebook
:
lastReceived
.
Cheque
.
Chequebook
.
String
(),
Payout
:
lastReceived
.
Cheque
.
CumulativePayout
,
Payout
:
bigint
.
Wrap
(
lastReceived
.
Cheque
.
CumulativePayout
)
,
}
}
}
}
...
@@ -160,7 +161,7 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, r *http.Reques
...
@@ -160,7 +161,7 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, r *http.Reques
LastSent
:
&
chequebookLastChequePeerResponse
{
LastSent
:
&
chequebookLastChequePeerResponse
{
Beneficiary
:
j
.
Cheque
.
Beneficiary
.
String
(),
Beneficiary
:
j
.
Cheque
.
Beneficiary
.
String
(),
Chequebook
:
j
.
Cheque
.
Chequebook
.
String
(),
Chequebook
:
j
.
Cheque
.
Chequebook
.
String
(),
Payout
:
j
.
Cheque
.
CumulativePayout
,
Payout
:
bigint
.
Wrap
(
j
.
Cheque
.
CumulativePayout
)
,
},
},
LastReceived
:
nil
,
LastReceived
:
nil
,
}
}
...
@@ -171,7 +172,7 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, r *http.Reques
...
@@ -171,7 +172,7 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, r *http.Reques
t
.
LastReceived
=
&
chequebookLastChequePeerResponse
{
t
.
LastReceived
=
&
chequebookLastChequePeerResponse
{
Beneficiary
:
j
.
Cheque
.
Beneficiary
.
String
(),
Beneficiary
:
j
.
Cheque
.
Beneficiary
.
String
(),
Chequebook
:
j
.
Cheque
.
Chequebook
.
String
(),
Chequebook
:
j
.
Cheque
.
Chequebook
.
String
(),
Payout
:
j
.
Cheque
.
CumulativePayout
,
Payout
:
bigint
.
Wrap
(
j
.
Cheque
.
CumulativePayout
)
,
}
}
lcr
[
i
]
=
t
lcr
[
i
]
=
t
}
else
{
}
else
{
...
@@ -181,7 +182,7 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, r *http.Reques
...
@@ -181,7 +182,7 @@ func (s *Service) chequebookAllLastHandler(w http.ResponseWriter, r *http.Reques
LastReceived
:
&
chequebookLastChequePeerResponse
{
LastReceived
:
&
chequebookLastChequePeerResponse
{
Beneficiary
:
j
.
Cheque
.
Beneficiary
.
String
(),
Beneficiary
:
j
.
Cheque
.
Beneficiary
.
String
(),
Chequebook
:
j
.
Cheque
.
Chequebook
.
String
(),
Chequebook
:
j
.
Cheque
.
Chequebook
.
String
(),
Payout
:
j
.
Cheque
.
CumulativePayout
,
Payout
:
bigint
.
Wrap
(
j
.
Cheque
.
CumulativePayout
)
,
},
},
}
}
}
}
...
@@ -246,7 +247,7 @@ func (s *Service) swapCashoutHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -246,7 +247,7 @@ func (s *Service) swapCashoutHandler(w http.ResponseWriter, r *http.Request) {
type
swapCashoutStatusResult
struct
{
type
swapCashoutStatusResult
struct
{
Recipient
common
.
Address
`json:"recipient"`
Recipient
common
.
Address
`json:"recipient"`
LastPayout
*
big
.
Int
`json:"lastPayout"`
LastPayout
*
big
int
.
BigInt
`json:"lastPayout"`
Bounced
bool
`json:"bounced"`
Bounced
bool
`json:"bounced"`
}
}
...
@@ -255,7 +256,7 @@ type swapCashoutStatusResponse struct {
...
@@ -255,7 +256,7 @@ type swapCashoutStatusResponse struct {
Cheque
*
chequebookLastChequePeerResponse
`json:"lastCashedCheque"`
Cheque
*
chequebookLastChequePeerResponse
`json:"lastCashedCheque"`
TransactionHash
*
common
.
Hash
`json:"transactionHash"`
TransactionHash
*
common
.
Hash
`json:"transactionHash"`
Result
*
swapCashoutStatusResult
`json:"result"`
Result
*
swapCashoutStatusResult
`json:"result"`
UncashedAmount
*
big
.
Int
`json:"uncashedAmount"`
UncashedAmount
*
big
int
.
BigInt
`json:"uncashedAmount"`
}
}
func
(
s
*
Service
)
swapCashoutStatusHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
s
*
Service
)
swapCashoutStatusHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -295,13 +296,13 @@ func (s *Service) swapCashoutStatusHandler(w http.ResponseWriter, r *http.Reques
...
@@ -295,13 +296,13 @@ func (s *Service) swapCashoutStatusHandler(w http.ResponseWriter, r *http.Reques
if
status
.
Last
.
Result
!=
nil
{
if
status
.
Last
.
Result
!=
nil
{
result
=
&
swapCashoutStatusResult
{
result
=
&
swapCashoutStatusResult
{
Recipient
:
status
.
Last
.
Result
.
Recipient
,
Recipient
:
status
.
Last
.
Result
.
Recipient
,
LastPayout
:
status
.
Last
.
Result
.
TotalPayout
,
LastPayout
:
bigint
.
Wrap
(
status
.
Last
.
Result
.
TotalPayout
)
,
Bounced
:
status
.
Last
.
Result
.
Bounced
,
Bounced
:
status
.
Last
.
Result
.
Bounced
,
}
}
}
}
chequeResponse
=
&
chequebookLastChequePeerResponse
{
chequeResponse
=
&
chequebookLastChequePeerResponse
{
Chequebook
:
status
.
Last
.
Cheque
.
Chequebook
.
String
(),
Chequebook
:
status
.
Last
.
Cheque
.
Chequebook
.
String
(),
Payout
:
status
.
Last
.
Cheque
.
CumulativePayout
,
Payout
:
bigint
.
Wrap
(
status
.
Last
.
Cheque
.
CumulativePayout
)
,
Beneficiary
:
status
.
Last
.
Cheque
.
Beneficiary
.
String
(),
Beneficiary
:
status
.
Last
.
Cheque
.
Beneficiary
.
String
(),
}
}
txHash
=
&
status
.
Last
.
TxHash
txHash
=
&
status
.
Last
.
TxHash
...
@@ -312,7 +313,7 @@ func (s *Service) swapCashoutStatusHandler(w http.ResponseWriter, r *http.Reques
...
@@ -312,7 +313,7 @@ func (s *Service) swapCashoutStatusHandler(w http.ResponseWriter, r *http.Reques
TransactionHash
:
txHash
,
TransactionHash
:
txHash
,
Cheque
:
chequeResponse
,
Cheque
:
chequeResponse
,
Result
:
result
,
Result
:
result
,
UncashedAmount
:
status
.
UncashedAmount
,
UncashedAmount
:
bigint
.
Wrap
(
status
.
UncashedAmount
)
,
})
})
}
}
...
...
pkg/debugapi/chequebook_test.go
View file @
7383d3dc
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
...
@@ -44,8 +45,8 @@ func TestChequebookBalance(t *testing.T) {
...
@@ -44,8 +45,8 @@ func TestChequebookBalance(t *testing.T) {
})
})
expected
:=
&
debugapi
.
ChequebookBalanceResponse
{
expected
:=
&
debugapi
.
ChequebookBalanceResponse
{
TotalBalance
:
returnedBalance
,
TotalBalance
:
bigint
.
Wrap
(
returnedBalance
)
,
AvailableBalance
:
returnedAvailableBalance
,
AvailableBalance
:
bigint
.
Wrap
(
returnedAvailableBalance
)
,
}
}
var
got
*
debugapi
.
ChequebookBalanceResponse
var
got
*
debugapi
.
ChequebookBalanceResponse
...
@@ -339,12 +340,12 @@ func TestChequebookLastCheques(t *testing.T) {
...
@@ -339,12 +340,12 @@ func TestChequebookLastCheques(t *testing.T) {
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary
.
String
(),
Beneficiary
:
beneficiary
.
String
(),
Chequebook
:
chequebookAddress1
.
String
(),
Chequebook
:
chequebookAddress1
.
String
(),
Payout
:
cumulativePayout4
,
Payout
:
bigint
.
Wrap
(
cumulativePayout4
)
,
},
},
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary1
.
String
(),
Beneficiary
:
beneficiary1
.
String
(),
Chequebook
:
chequebookAddress1
.
String
(),
Chequebook
:
chequebookAddress1
.
String
(),
Payout
:
cumulativePayout1
,
Payout
:
bigint
.
Wrap
(
cumulativePayout1
)
,
},
},
},
},
{
{
...
@@ -353,7 +354,7 @@ func TestChequebookLastCheques(t *testing.T) {
...
@@ -353,7 +354,7 @@ func TestChequebookLastCheques(t *testing.T) {
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary2
.
String
(),
Beneficiary
:
beneficiary2
.
String
(),
Chequebook
:
chequebookAddress2
.
String
(),
Chequebook
:
chequebookAddress2
.
String
(),
Payout
:
cumulativePayout2
,
Payout
:
bigint
.
Wrap
(
cumulativePayout2
)
,
},
},
},
},
{
{
...
@@ -362,7 +363,7 @@ func TestChequebookLastCheques(t *testing.T) {
...
@@ -362,7 +363,7 @@ func TestChequebookLastCheques(t *testing.T) {
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary3
.
String
(),
Beneficiary
:
beneficiary3
.
String
(),
Chequebook
:
chequebookAddress3
.
String
(),
Chequebook
:
chequebookAddress3
.
String
(),
Payout
:
cumulativePayout3
,
Payout
:
bigint
.
Wrap
(
cumulativePayout3
)
,
},
},
},
},
{
{
...
@@ -370,7 +371,7 @@ func TestChequebookLastCheques(t *testing.T) {
...
@@ -370,7 +371,7 @@ func TestChequebookLastCheques(t *testing.T) {
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary
.
String
(),
Beneficiary
:
beneficiary
.
String
(),
Chequebook
:
chequebookAddress4
.
String
(),
Chequebook
:
chequebookAddress4
.
String
(),
Payout
:
cumulativePayout5
,
Payout
:
bigint
.
Wrap
(
cumulativePayout5
)
,
},
},
LastSent
:
nil
,
LastSent
:
nil
,
},
},
...
@@ -379,7 +380,7 @@ func TestChequebookLastCheques(t *testing.T) {
...
@@ -379,7 +380,7 @@ func TestChequebookLastCheques(t *testing.T) {
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary
.
String
(),
Beneficiary
:
beneficiary
.
String
(),
Chequebook
:
chequebookAddress5
.
String
(),
Chequebook
:
chequebookAddress5
.
String
(),
Payout
:
cumulativePayout6
,
Payout
:
bigint
.
Wrap
(
cumulativePayout6
)
,
},
},
LastSent
:
nil
,
LastSent
:
nil
,
},
},
...
@@ -450,12 +451,12 @@ func TestChequebookLastChequesPeer(t *testing.T) {
...
@@ -450,12 +451,12 @@ func TestChequebookLastChequesPeer(t *testing.T) {
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastReceived
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary0
.
String
(),
Beneficiary
:
beneficiary0
.
String
(),
Chequebook
:
chequebookAddress
.
String
(),
Chequebook
:
chequebookAddress
.
String
(),
Payout
:
cumulativePayout2
,
Payout
:
bigint
.
Wrap
(
cumulativePayout2
)
,
},
},
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
LastSent
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Beneficiary
:
beneficiary1
.
String
(),
Beneficiary
:
beneficiary1
.
String
(),
Chequebook
:
chequebookAddress
.
String
(),
Chequebook
:
chequebookAddress
.
String
(),
Payout
:
cumulativePayout1
,
Payout
:
bigint
.
Wrap
(
cumulativePayout1
)
,
},
},
}
}
...
@@ -589,15 +590,15 @@ func TestChequebookCashoutStatus(t *testing.T) {
...
@@ -589,15 +590,15 @@ func TestChequebookCashoutStatus(t *testing.T) {
TransactionHash
:
&
actionTxHash
,
TransactionHash
:
&
actionTxHash
,
Cheque
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Cheque
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Chequebook
:
chequebookAddress
.
String
(),
Chequebook
:
chequebookAddress
.
String
(),
Payout
:
cumulativePayout
,
Payout
:
bigint
.
Wrap
(
cumulativePayout
)
,
Beneficiary
:
cheque
.
Beneficiary
.
String
(),
Beneficiary
:
cheque
.
Beneficiary
.
String
(),
},
},
Result
:
&
debugapi
.
SwapCashoutStatusResult
{
Result
:
&
debugapi
.
SwapCashoutStatusResult
{
Recipient
:
recipientAddress
,
Recipient
:
recipientAddress
,
LastPayout
:
totalPayout
,
LastPayout
:
bigint
.
Wrap
(
totalPayout
)
,
Bounced
:
false
,
Bounced
:
false
,
},
},
UncashedAmount
:
uncashedAmount
,
UncashedAmount
:
bigint
.
Wrap
(
uncashedAmount
)
,
}
}
var
got
*
debugapi
.
SwapCashoutStatusResponse
var
got
*
debugapi
.
SwapCashoutStatusResponse
...
@@ -633,11 +634,11 @@ func TestChequebookCashoutStatus(t *testing.T) {
...
@@ -633,11 +634,11 @@ func TestChequebookCashoutStatus(t *testing.T) {
TransactionHash
:
&
actionTxHash
,
TransactionHash
:
&
actionTxHash
,
Cheque
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Cheque
:
&
debugapi
.
ChequebookLastChequePeerResponse
{
Chequebook
:
chequebookAddress
.
String
(),
Chequebook
:
chequebookAddress
.
String
(),
Payout
:
cumulativePayout
,
Payout
:
bigint
.
Wrap
(
cumulativePayout
)
,
Beneficiary
:
cheque
.
Beneficiary
.
String
(),
Beneficiary
:
cheque
.
Beneficiary
.
String
(),
},
},
Result
:
nil
,
Result
:
nil
,
UncashedAmount
:
uncashedAmount
,
UncashedAmount
:
bigint
.
Wrap
(
uncashedAmount
)
,
}
}
var
got
*
debugapi
.
SwapCashoutStatusResponse
var
got
*
debugapi
.
SwapCashoutStatusResponse
...
@@ -668,7 +669,7 @@ func TestChequebookCashoutStatus(t *testing.T) {
...
@@ -668,7 +669,7 @@ func TestChequebookCashoutStatus(t *testing.T) {
TransactionHash
:
nil
,
TransactionHash
:
nil
,
Cheque
:
nil
,
Cheque
:
nil
,
Result
:
nil
,
Result
:
nil
,
UncashedAmount
:
uncashedAmount
,
UncashedAmount
:
bigint
.
Wrap
(
uncashedAmount
)
,
}
}
var
got
*
debugapi
.
SwapCashoutStatusResponse
var
got
*
debugapi
.
SwapCashoutStatusResponse
...
...
pkg/debugapi/export_test.go
View file @
7383d3dc
...
@@ -26,6 +26,8 @@ type (
...
@@ -26,6 +26,8 @@ type (
SwapCashoutStatusResponse
=
swapCashoutStatusResponse
SwapCashoutStatusResponse
=
swapCashoutStatusResponse
SwapCashoutStatusResult
=
swapCashoutStatusResult
SwapCashoutStatusResult
=
swapCashoutStatusResult
TagResponse
=
tagResponse
TagResponse
=
tagResponse
ReserveStateResponse
=
reserveStateResponse
ChainStateResponse
=
chainStateResponse
)
)
var
(
var
(
...
...
pkg/debugapi/postage.go
View file @
7383d3dc
...
@@ -7,14 +7,41 @@ package debugapi
...
@@ -7,14 +7,41 @@ package debugapi
import
(
import
(
"net/http"
"net/http"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
)
)
type
reserveStateResponse
struct
{
Radius
uint8
`json:"radius"`
Available
int64
`json:"available"`
Outer
*
bigint
.
BigInt
`json:"outer"`
// lower value limit for outer layer = the further half of chunks
Inner
*
bigint
.
BigInt
`json:"inner"`
}
type
chainStateResponse
struct
{
Block
uint64
`json:"block"`
// The block number of the last postage event.
TotalAmount
*
bigint
.
BigInt
`json:"totalAmount"`
// Cumulative amount paid per stamp.
CurrentPrice
*
bigint
.
BigInt
`json:"currentPrice"`
// Bzz/chunk/block normalised price.
}
func
(
s
*
Service
)
reserveStateHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
func
(
s
*
Service
)
reserveStateHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
jsonhttp
.
OK
(
w
,
s
.
batchStore
.
GetReserveState
())
state
:=
s
.
batchStore
.
GetReserveState
()
jsonhttp
.
OK
(
w
,
reserveStateResponse
{
Radius
:
state
.
Radius
,
Available
:
state
.
Available
,
Outer
:
bigint
.
Wrap
(
state
.
Outer
),
Inner
:
bigint
.
Wrap
(
state
.
Inner
),
})
}
}
// chainStateHandler returns the current chain state.
// chainStateHandler returns the current chain state.
func
(
s
*
Service
)
chainStateHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
func
(
s
*
Service
)
chainStateHandler
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
jsonhttp
.
OK
(
w
,
s
.
batchStore
.
GetChainState
())
state
:=
s
.
batchStore
.
GetChainState
()
jsonhttp
.
OK
(
w
,
chainStateResponse
{
Block
:
state
.
Block
,
TotalAmount
:
bigint
.
Wrap
(
state
.
TotalAmount
),
CurrentPrice
:
bigint
.
Wrap
(
state
.
CurrentPrice
),
})
}
}
pkg/debugapi/postage_test.go
View file @
7383d3dc
...
@@ -9,6 +9,8 @@ import (
...
@@ -9,6 +9,8 @@ import (
"net/http"
"net/http"
"testing"
"testing"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/postage/batchstore/mock"
"github.com/ethersphere/bee/pkg/postage/batchstore/mock"
...
@@ -19,11 +21,15 @@ func TestReserveState(t *testing.T) {
...
@@ -19,11 +21,15 @@ func TestReserveState(t *testing.T) {
ts
:=
newTestServer
(
t
,
testServerOptions
{
ts
:=
newTestServer
(
t
,
testServerOptions
{
BatchStore
:
mock
.
New
(
mock
.
WithReserveState
(
&
postage
.
ReserveState
{
BatchStore
:
mock
.
New
(
mock
.
WithReserveState
(
&
postage
.
ReserveState
{
Radius
:
5
,
Radius
:
5
,
Outer
:
big
.
NewInt
(
5
),
Inner
:
big
.
NewInt
(
5
),
})),
})),
})
})
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/reservestate"
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/reservestate"
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
&
postage
.
ReserveStat
e
{
jsonhttptest
.
WithExpectedJSONResponse
(
&
debugapi
.
ReserveStateRespons
e
{
Radius
:
5
,
Radius
:
5
,
Outer
:
bigint
.
Wrap
(
big
.
NewInt
(
5
)),
Inner
:
bigint
.
Wrap
(
big
.
NewInt
(
5
)),
}),
}),
)
)
})
})
...
@@ -32,7 +38,7 @@ func TestReserveState(t *testing.T) {
...
@@ -32,7 +38,7 @@ func TestReserveState(t *testing.T) {
BatchStore
:
mock
.
New
(),
BatchStore
:
mock
.
New
(),
})
})
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/reservestate"
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/reservestate"
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
&
postage
.
ReserveStat
e
{}),
jsonhttptest
.
WithExpectedJSONResponse
(
&
debugapi
.
ReserveStateRespons
e
{}),
)
)
})
})
}
}
...
@@ -48,7 +54,11 @@ func TestChainState(t *testing.T) {
...
@@ -48,7 +54,11 @@ func TestChainState(t *testing.T) {
BatchStore
:
mock
.
New
(
mock
.
WithChainState
(
cs
)),
BatchStore
:
mock
.
New
(
mock
.
WithChainState
(
cs
)),
})
})
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/chainstate"
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/chainstate"
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
cs
),
jsonhttptest
.
WithExpectedJSONResponse
(
&
debugapi
.
ChainStateResponse
{
Block
:
123456
,
TotalAmount
:
bigint
.
Wrap
(
big
.
NewInt
(
50
)),
CurrentPrice
:
bigint
.
Wrap
(
big
.
NewInt
(
5
)),
}),
)
)
})
})
...
@@ -57,7 +67,7 @@ func TestChainState(t *testing.T) {
...
@@ -57,7 +67,7 @@ func TestChainState(t *testing.T) {
BatchStore
:
mock
.
New
(),
BatchStore
:
mock
.
New
(),
})
})
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/chainstate"
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
ts
.
Client
,
http
.
MethodGet
,
"/chainstate"
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
&
postage
.
ChainStat
e
{}),
jsonhttptest
.
WithExpectedJSONResponse
(
&
debugapi
.
ChainStateRespons
e
{}),
)
)
})
})
}
}
pkg/debugapi/settlements.go
View file @
7383d3dc
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"math/big"
"math/big"
"net/http"
"net/http"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/settlement"
"github.com/ethersphere/bee/pkg/settlement"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
...
@@ -21,14 +22,14 @@ var (
...
@@ -21,14 +22,14 @@ var (
)
)
type
settlementResponse
struct
{
type
settlementResponse
struct
{
Peer
string
`json:"peer"`
Peer
string
`json:"peer"`
SettlementReceived
*
big
.
Int
`json:"received"`
SettlementReceived
*
big
int
.
Big
Int
`json:"received"`
SettlementSent
*
big
.
Int
`json:"sent"`
SettlementSent
*
big
int
.
Big
Int
`json:"sent"`
}
}
type
settlementsResponse
struct
{
type
settlementsResponse
struct
{
TotalSettlementReceived
*
big
.
Int
`json:"totalReceived"`
TotalSettlementReceived
*
big
int
.
BigInt
`json:"totalReceived"`
TotalSettlementSent
*
big
.
Int
`json:"totalSent"`
TotalSettlementSent
*
big
int
.
BigInt
`json:"totalSent"`
Settlements
[]
settlementResponse
`json:"settlements"`
Settlements
[]
settlementResponse
`json:"settlements"`
}
}
...
@@ -57,8 +58,8 @@ func (s *Service) settlementsHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -57,8 +58,8 @@ func (s *Service) settlementsHandler(w http.ResponseWriter, r *http.Request) {
for
a
,
b
:=
range
settlementsSent
{
for
a
,
b
:=
range
settlementsSent
{
settlementResponses
[
a
]
=
settlementResponse
{
settlementResponses
[
a
]
=
settlementResponse
{
Peer
:
a
,
Peer
:
a
,
SettlementSent
:
b
,
SettlementSent
:
b
igint
.
Wrap
(
b
)
,
SettlementReceived
:
big
.
NewInt
(
0
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
}
}
totalSent
.
Add
(
b
,
totalSent
)
totalSent
.
Add
(
b
,
totalSent
)
}
}
...
@@ -66,13 +67,13 @@ func (s *Service) settlementsHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -66,13 +67,13 @@ func (s *Service) settlementsHandler(w http.ResponseWriter, r *http.Request) {
for
a
,
b
:=
range
settlementsReceived
{
for
a
,
b
:=
range
settlementsReceived
{
if
_
,
ok
:=
settlementResponses
[
a
];
ok
{
if
_
,
ok
:=
settlementResponses
[
a
];
ok
{
t
:=
settlementResponses
[
a
]
t
:=
settlementResponses
[
a
]
t
.
SettlementReceived
=
b
t
.
SettlementReceived
=
b
igint
.
Wrap
(
b
)
settlementResponses
[
a
]
=
t
settlementResponses
[
a
]
=
t
}
else
{
}
else
{
settlementResponses
[
a
]
=
settlementResponse
{
settlementResponses
[
a
]
=
settlementResponse
{
Peer
:
a
,
Peer
:
a
,
SettlementSent
:
big
.
NewInt
(
0
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
SettlementReceived
:
b
,
SettlementReceived
:
b
igint
.
Wrap
(
b
)
,
}
}
}
}
totalReceived
.
Add
(
b
,
totalReceived
)
totalReceived
.
Add
(
b
,
totalReceived
)
...
@@ -85,7 +86,7 @@ func (s *Service) settlementsHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -85,7 +86,7 @@ func (s *Service) settlementsHandler(w http.ResponseWriter, r *http.Request) {
i
++
i
++
}
}
jsonhttp
.
OK
(
w
,
settlementsResponse
{
TotalSettlementReceived
:
totalReceived
,
TotalSettlementSent
:
totalSent
,
Settlements
:
settlementResponsesArray
})
jsonhttp
.
OK
(
w
,
settlementsResponse
{
TotalSettlementReceived
:
bigint
.
Wrap
(
totalReceived
),
TotalSettlementSent
:
bigint
.
Wrap
(
totalSent
)
,
Settlements
:
settlementResponsesArray
})
}
}
func
(
s
*
Service
)
peerSettlementsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
s
*
Service
)
peerSettlementsHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
@@ -139,8 +140,8 @@ func (s *Service) peerSettlementsHandler(w http.ResponseWriter, r *http.Request)
...
@@ -139,8 +140,8 @@ func (s *Service) peerSettlementsHandler(w http.ResponseWriter, r *http.Request)
jsonhttp
.
OK
(
w
,
settlementResponse
{
jsonhttp
.
OK
(
w
,
settlementResponse
{
Peer
:
peer
.
String
(),
Peer
:
peer
.
String
(),
SettlementReceived
:
received
,
SettlementReceived
:
bigint
.
Wrap
(
received
)
,
SettlementSent
:
sent
,
SettlementSent
:
bigint
.
Wrap
(
sent
)
,
})
})
}
}
...
@@ -169,8 +170,8 @@ func (s *Service) settlementsHandlerPseudosettle(w http.ResponseWriter, r *http.
...
@@ -169,8 +170,8 @@ func (s *Service) settlementsHandlerPseudosettle(w http.ResponseWriter, r *http.
for
a
,
b
:=
range
settlementsSent
{
for
a
,
b
:=
range
settlementsSent
{
settlementResponses
[
a
]
=
settlementResponse
{
settlementResponses
[
a
]
=
settlementResponse
{
Peer
:
a
,
Peer
:
a
,
SettlementSent
:
b
,
SettlementSent
:
b
igint
.
Wrap
(
b
)
,
SettlementReceived
:
big
.
NewInt
(
0
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
}
}
totalSent
.
Add
(
b
,
totalSent
)
totalSent
.
Add
(
b
,
totalSent
)
}
}
...
@@ -178,13 +179,13 @@ func (s *Service) settlementsHandlerPseudosettle(w http.ResponseWriter, r *http.
...
@@ -178,13 +179,13 @@ func (s *Service) settlementsHandlerPseudosettle(w http.ResponseWriter, r *http.
for
a
,
b
:=
range
settlementsReceived
{
for
a
,
b
:=
range
settlementsReceived
{
if
_
,
ok
:=
settlementResponses
[
a
];
ok
{
if
_
,
ok
:=
settlementResponses
[
a
];
ok
{
t
:=
settlementResponses
[
a
]
t
:=
settlementResponses
[
a
]
t
.
SettlementReceived
=
b
t
.
SettlementReceived
=
b
igint
.
Wrap
(
b
)
settlementResponses
[
a
]
=
t
settlementResponses
[
a
]
=
t
}
else
{
}
else
{
settlementResponses
[
a
]
=
settlementResponse
{
settlementResponses
[
a
]
=
settlementResponse
{
Peer
:
a
,
Peer
:
a
,
SettlementSent
:
big
.
NewInt
(
0
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
SettlementReceived
:
b
,
SettlementReceived
:
b
igint
.
Wrap
(
b
)
,
}
}
}
}
totalReceived
.
Add
(
b
,
totalReceived
)
totalReceived
.
Add
(
b
,
totalReceived
)
...
@@ -197,5 +198,5 @@ func (s *Service) settlementsHandlerPseudosettle(w http.ResponseWriter, r *http.
...
@@ -197,5 +198,5 @@ func (s *Service) settlementsHandlerPseudosettle(w http.ResponseWriter, r *http.
i
++
i
++
}
}
jsonhttp
.
OK
(
w
,
settlementsResponse
{
TotalSettlementReceived
:
totalReceived
,
TotalSettlementSent
:
totalSent
,
Settlements
:
settlementResponsesArray
})
jsonhttp
.
OK
(
w
,
settlementsResponse
{
TotalSettlementReceived
:
bigint
.
Wrap
(
totalReceived
),
TotalSettlementSent
:
bigint
.
Wrap
(
totalSent
)
,
Settlements
:
settlementResponsesArray
})
}
}
pkg/debugapi/settlements_test.go
View file @
7383d3dc
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"reflect"
"reflect"
"testing"
"testing"
"github.com/ethersphere/bee/pkg/bigint"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
...
@@ -40,28 +41,28 @@ func TestSettlements(t *testing.T) {
...
@@ -40,28 +41,28 @@ func TestSettlements(t *testing.T) {
})
})
expected
:=
&
debugapi
.
SettlementsResponse
{
expected
:=
&
debugapi
.
SettlementsResponse
{
TotalSettlementReceived
:
big
.
NewInt
(
15000
),
TotalSettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
15000
)
),
TotalSettlementSent
:
big
.
NewInt
(
80000
),
TotalSettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
80000
)
),
Settlements
:
[]
debugapi
.
SettlementResponse
{
Settlements
:
[]
debugapi
.
SettlementResponse
{
{
{
Peer
:
"DEAD"
,
Peer
:
"DEAD"
,
SettlementReceived
:
big
.
NewInt
(
0
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
SettlementSent
:
big
.
NewInt
(
10000
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
10000
)
),
},
},
{
{
Peer
:
"BEEF"
,
Peer
:
"BEEF"
,
SettlementReceived
:
big
.
NewInt
(
10000
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
10000
)
),
SettlementSent
:
big
.
NewInt
(
20000
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
20000
)
),
},
},
{
{
Peer
:
"FFFF"
,
Peer
:
"FFFF"
,
SettlementReceived
:
big
.
NewInt
(
0
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
SettlementSent
:
big
.
NewInt
(
50000
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
50000
)
),
},
},
{
{
Peer
:
"EEEE"
,
Peer
:
"EEEE"
,
SettlementReceived
:
big
.
NewInt
(
5000
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
5000
)
),
SettlementSent
:
big
.
NewInt
(
0
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
},
},
},
},
}
}
...
@@ -107,8 +108,8 @@ func TestSettlementsPeers(t *testing.T) {
...
@@ -107,8 +108,8 @@ func TestSettlementsPeers(t *testing.T) {
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/settlements/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/settlements/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
SettlementResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
SettlementResponse
{
Peer
:
peer
,
Peer
:
peer
,
SettlementSent
:
big
.
NewInt
(
1000000000000000000
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
1000000000000000000
)
),
SettlementReceived
:
big
.
NewInt
(
0
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
}),
}),
)
)
}
}
...
@@ -133,8 +134,8 @@ func TestSettlementsPeersNoSettlements(t *testing.T) {
...
@@ -133,8 +134,8 @@ func TestSettlementsPeersNoSettlements(t *testing.T) {
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/settlements/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/settlements/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
SettlementResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
SettlementResponse
{
Peer
:
peer
,
Peer
:
peer
,
SettlementSent
:
big
.
NewInt
(
0
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
SettlementReceived
:
big
.
NewInt
(
1000000000000000000
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
1000000000000000000
)
),
}),
}),
)
)
})
})
...
@@ -150,8 +151,8 @@ func TestSettlementsPeersNoSettlements(t *testing.T) {
...
@@ -150,8 +151,8 @@ func TestSettlementsPeersNoSettlements(t *testing.T) {
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/settlements/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
Request
(
t
,
testServer
.
Client
,
http
.
MethodGet
,
"/settlements/"
+
peer
,
http
.
StatusOK
,
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
SettlementResponse
{
jsonhttptest
.
WithExpectedJSONResponse
(
debugapi
.
SettlementResponse
{
Peer
:
peer
,
Peer
:
peer
,
SettlementSent
:
big
.
NewInt
(
1000000000000000000
),
SettlementSent
:
big
int
.
Wrap
(
big
.
NewInt
(
1000000000000000000
)
),
SettlementReceived
:
big
.
NewInt
(
0
),
SettlementReceived
:
big
int
.
Wrap
(
big
.
NewInt
(
0
)
),
}),
}),
)
)
})
})
...
@@ -217,11 +218,11 @@ func equalSettlements(a, b *debugapi.SettlementsResponse) bool {
...
@@ -217,11 +218,11 @@ func equalSettlements(a, b *debugapi.SettlementsResponse) bool {
}
}
}
}
if
a
.
TotalSettlementReceived
.
Cmp
(
b
.
TotalSettlementReceived
)
!=
0
{
if
a
.
TotalSettlementReceived
.
Cmp
(
b
.
TotalSettlementReceived
.
Int
)
!=
0
{
return
false
return
false
}
}
if
a
.
TotalSettlementSent
.
Cmp
(
b
.
TotalSettlementSent
)
!=
0
{
if
a
.
TotalSettlementSent
.
Cmp
(
b
.
TotalSettlementSent
.
Int
)
!=
0
{
return
false
return
false
}
}
...
...
pkg/postage/chainstate.go
View file @
7383d3dc
...
@@ -8,7 +8,7 @@ import "math/big"
...
@@ -8,7 +8,7 @@ import "math/big"
// ChainState contains data the batch service reads from the chain.
// ChainState contains data the batch service reads from the chain.
type
ChainState
struct
{
type
ChainState
struct
{
Block
uint64
`json:"block"`
// The block number of the last postage event.
Block
uint64
// The block number of the last postage event.
TotalAmount
*
big
.
Int
`json:"totalAmount"`
// Cumulative amount paid per stamp.
TotalAmount
*
big
.
Int
// Cumulative amount paid per stamp.
CurrentPrice
*
big
.
Int
`json:"currentPrice"`
// Bzz/chunk/block normalised price.
CurrentPrice
*
big
.
Int
// Bzz/chunk/block normalised price.
}
}
pkg/postage/reservestate.go
View file @
7383d3dc
...
@@ -7,8 +7,8 @@ package postage
...
@@ -7,8 +7,8 @@ package postage
import
"math/big"
import
"math/big"
type
ReserveState
struct
{
type
ReserveState
struct
{
Radius
uint8
`json:"radius"`
Radius
uint8
Available
int64
`json:"available"`
Available
int64
Outer
*
big
.
Int
`json:"outer"`
// lower value limit for outer layer = the further half of chunks
Outer
*
big
.
Int
// lower value limit for outer layer = the further half of chunks
Inner
*
big
.
Int
`json:"inner"`
Inner
*
big
.
Int
}
}
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