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
2bd06796
Unverified
Commit
2bd06796
authored
May 19, 2021
by
Ralph Pichler
Committed by
GitHub
May 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: allow specifying gasprice for postage stamp creation (#1769)
parent
0903f2c3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
4 deletions
+54
-4
Swarm.yaml
openapi/Swarm.yaml
+1
-0
postage.go
pkg/api/postage.go
+18
-1
postage_test.go
pkg/api/postage_test.go
+31
-0
router.go
pkg/api/router.go
+1
-1
contract.go
pkg/postage/postagecontract/contract.go
+3
-2
No files found.
openapi/Swarm.yaml
View file @
2bd06796
...
...
@@ -785,6 +785,7 @@ paths:
type
:
string
required
:
false
description
:
An optional label for this batch
-
$ref
:
"
SwarmCommon.yaml#/components/parameters/GasPriceParameter"
responses
:
"
201"
:
description
:
Returns the newly created postage batch ID
...
...
pkg/api/postage.go
View file @
2bd06796
...
...
@@ -14,9 +14,15 @@ import (
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/postage/postagecontract"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/gorilla/mux"
)
const
(
gasPriceHeader
=
"Gas-Price"
errBadGasPrice
=
"bad gas price"
)
type
batchID
[]
byte
func
(
b
batchID
)
MarshalJSON
()
([]
byte
,
error
)
{
...
...
@@ -48,7 +54,18 @@ func (s *server) postageCreateHandler(w http.ResponseWriter, r *http.Request) {
label
:=
r
.
URL
.
Query
()
.
Get
(
"label"
)
batchID
,
err
:=
s
.
postageContract
.
CreateBatch
(
r
.
Context
(),
amount
,
uint8
(
depth
),
label
)
ctx
:=
r
.
Context
()
if
price
,
ok
:=
r
.
Header
[
gasPriceHeader
];
ok
{
p
,
ok
:=
big
.
NewInt
(
0
)
.
SetString
(
price
[
0
],
10
)
if
!
ok
{
s
.
logger
.
Error
(
"create batch: bad gas price"
)
jsonhttp
.
BadRequest
(
w
,
errBadGasPrice
)
return
}
ctx
=
sctx
.
SetGasPrice
(
ctx
,
p
)
}
batchID
,
err
:=
s
.
postageContract
.
CreateBatch
(
ctx
,
amount
,
uint8
(
depth
),
label
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
postagecontract
.
ErrInsufficientFunds
)
{
s
.
logger
.
Debugf
(
"create batch: out of funds: %v"
,
err
)
...
...
pkg/api/postage_test.go
View file @
2bd06796
...
...
@@ -20,6 +20,7 @@ import (
mockpost
"github.com/ethersphere/bee/pkg/postage/mock"
"github.com/ethersphere/bee/pkg/postage/postagecontract"
contractMock
"github.com/ethersphere/bee/pkg/postage/postagecontract/mock"
"github.com/ethersphere/bee/pkg/sctx"
)
func
TestPostageCreateStamp
(
t
*
testing
.
T
)
{
...
...
@@ -57,6 +58,36 @@ func TestPostageCreateStamp(t *testing.T) {
)
})
t
.
Run
(
"with-custom-gas"
,
func
(
t
*
testing
.
T
)
{
contract
:=
contractMock
.
New
(
contractMock
.
WithCreateBatchFunc
(
func
(
ctx
context
.
Context
,
ib
*
big
.
Int
,
d
uint8
,
l
string
)
([]
byte
,
error
)
{
if
ib
.
Cmp
(
big
.
NewInt
(
initialBalance
))
!=
0
{
return
nil
,
fmt
.
Errorf
(
"called with wrong initial balance. wanted %d, got %d"
,
initialBalance
,
ib
)
}
if
d
!=
depth
{
return
nil
,
fmt
.
Errorf
(
"called with wrong depth. wanted %d, got %d"
,
depth
,
d
)
}
if
l
!=
label
{
return
nil
,
fmt
.
Errorf
(
"called with wrong label. wanted %s, got %s"
,
label
,
l
)
}
if
sctx
.
GetGasPrice
(
ctx
)
.
Cmp
(
big
.
NewInt
(
10000
))
!=
0
{
return
nil
,
fmt
.
Errorf
(
"called with wrong gas price. wanted %d, got %d"
,
10000
,
sctx
.
GetGasPrice
(
ctx
))
}
return
batchID
,
nil
}),
)
client
,
_
,
_
:=
newTestServer
(
t
,
testServerOptions
{
PostageContract
:
contract
,
})
jsonhttptest
.
Request
(
t
,
client
,
http
.
MethodPost
,
createBatch
(
initialBalance
,
depth
,
label
),
http
.
StatusCreated
,
jsonhttptest
.
WithRequestHeader
(
"Gas-Price"
,
"10000"
),
jsonhttptest
.
WithExpectedJSONResponse
(
&
api
.
PostageCreateResponse
{
BatchID
:
batchID
,
}),
)
})
t
.
Run
(
"with-error"
,
func
(
t
*
testing
.
T
)
{
contract
:=
contractMock
.
New
(
contractMock
.
WithCreateBatchFunc
(
func
(
ctx
context
.
Context
,
ib
*
big
.
Int
,
d
uint8
,
l
string
)
([]
byte
,
error
)
{
...
...
pkg/api/router.go
View file @
2bd06796
...
...
@@ -188,7 +188,7 @@ func (s *server) setupRouting() {
if
o
:=
r
.
Header
.
Get
(
"Origin"
);
o
!=
""
&&
s
.
checkOrigin
(
r
)
{
w
.
Header
()
.
Set
(
"Access-Control-Allow-Credentials"
,
"true"
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
o
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Headers"
,
"Origin, Accept, Authorization, Content-Type, X-Requested-With, Access-Control-Request-Headers, Access-Control-Request-Method, Swarm-Tag, Swarm-Pin, Swarm-Encrypt, Swarm-Index-Document, Swarm-Error-Document, Swarm-Collection, Swarm-Postage-Batch-Id"
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Headers"
,
"Origin, Accept, Authorization, Content-Type, X-Requested-With, Access-Control-Request-Headers, Access-Control-Request-Method, Swarm-Tag, Swarm-Pin, Swarm-Encrypt, Swarm-Index-Document, Swarm-Error-Document, Swarm-Collection, Swarm-Postage-Batch-Id
, Gas-Price
"
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Methods"
,
"GET, HEAD, OPTIONS, POST, PUT, DELETE"
)
w
.
Header
()
.
Set
(
"Access-Control-Max-Age"
,
"3600"
)
}
...
...
pkg/postage/postagecontract/contract.go
View file @
2bd06796
...
...
@@ -16,6 +16,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/settlement/swap/transaction"
"github.com/ethersphere/go-storage-incentives-abi/postageabi"
"github.com/ethersphere/go-sw3-abi/sw3abi"
...
...
@@ -70,7 +71,7 @@ func (c *postageContract) sendApproveTransaction(ctx context.Context, amount *bi
txHash
,
err
:=
c
.
transactionService
.
Send
(
ctx
,
&
transaction
.
TxRequest
{
To
:
&
c
.
bzzTokenAddress
,
Data
:
callData
,
GasPrice
:
nil
,
GasPrice
:
sctx
.
GetGasPrice
(
ctx
)
,
GasLimit
:
0
,
Value
:
big
.
NewInt
(
0
),
})
...
...
@@ -99,7 +100,7 @@ func (c *postageContract) sendCreateBatchTransaction(ctx context.Context, owner
request
:=
&
transaction
.
TxRequest
{
To
:
&
c
.
postageContractAddress
,
Data
:
callData
,
GasPrice
:
nil
,
GasPrice
:
sctx
.
GetGasPrice
(
ctx
)
,
GasLimit
:
0
,
Value
:
big
.
NewInt
(
0
),
}
...
...
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