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
68e0b591
Unverified
Commit
68e0b591
authored
May 19, 2021
by
Ralph Pichler
Committed by
GitHub
May 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: new postage contracts (#1781)
parent
d4fcf466
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
44 deletions
+37
-44
cmd.go
cmd/bee/cmd/cmd.go
+0
-2
start.go
cmd/bee/cmd/start.go
+0
-1
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-2
node.go
pkg/node/node.go
+3
-10
export_test.go
pkg/postage/listener/export_test.go
+0
-1
listener.go
pkg/postage/listener/listener.go
+18
-20
listener_test.go
pkg/postage/listener/listener_test.go
+13
-7
No files found.
cmd/bee/cmd/cmd.go
View file @
68e0b591
...
...
@@ -62,7 +62,6 @@ const (
optionNameTransactionHash
=
"transaction"
optionNameFullNode
=
"full-node"
optionNamePostageContractAddress
=
"postage-stamp-address"
optionNamePriceOracleAddress
=
"price-oracle-address"
optionNameBlockTime
=
"block-time"
)
...
...
@@ -233,7 +232,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
Bool
(
optionNameSwapEnable
,
true
,
"enable swap"
)
cmd
.
Flags
()
.
Bool
(
optionNameFullNode
,
false
,
"cause the node to start in full mode"
)
cmd
.
Flags
()
.
String
(
optionNamePostageContractAddress
,
""
,
"postage stamp contract address"
)
cmd
.
Flags
()
.
String
(
optionNamePriceOracleAddress
,
""
,
"price oracle address"
)
cmd
.
Flags
()
.
String
(
optionNameTransactionHash
,
""
,
"proof-of-identity transaction hash"
)
cmd
.
Flags
()
.
Uint64
(
optionNameBlockTime
,
15
,
"chain block time"
)
}
...
...
cmd/bee/cmd/start.go
View file @
68e0b591
...
...
@@ -152,7 +152,6 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
FullNodeMode
:
fullNode
,
Transaction
:
c
.
config
.
GetString
(
optionNameTransactionHash
),
PostageContractAddress
:
c
.
config
.
GetString
(
optionNamePostageContractAddress
),
PriceOracleAddress
:
c
.
config
.
GetString
(
optionNamePriceOracleAddress
),
BlockTime
:
c
.
config
.
GetUint64
(
optionNameBlockTime
),
})
if
err
!=
nil
{
...
...
go.mod
View file @
68e0b591
...
...
@@ -8,7 +8,7 @@ require (
github.com/coreos/go-semver v0.3.0
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/ethereum/go-ethereum v1.9.23
github.com/ethersphere/go-storage-incentives-abi v0.
1
.0
github.com/ethersphere/go-storage-incentives-abi v0.
2
.0
github.com/ethersphere/go-sw3-abi v0.4.0
github.com/ethersphere/langos v1.0.0
github.com/gogo/protobuf v1.3.1
...
...
go.sum
View file @
68e0b591
...
...
@@ -160,8 +160,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0IdYEkbtw=
github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
github.com/ethersphere/go-storage-incentives-abi v0.
1.0 h1:yxNME3q5dha/pUtIYB07DALhhQjd3+uYhGLFqKMXVyg
=
github.com/ethersphere/go-storage-incentives-abi v0.
1
.0/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-storage-incentives-abi v0.
2.0 h1:TZ15auzGsdzuzUR2b5dLAMpFixorb4uKUDGF0QnVmmU
=
github.com/ethersphere/go-storage-incentives-abi v0.
2
.0/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.4.0 h1:T3ANY+ktWrPAwe2U0tZi+DILpkHzto5ym/XwV/Bbz8g=
github.com/ethersphere/go-sw3-abi v0.4.0/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
...
...
pkg/node/node.go
View file @
68e0b591
...
...
@@ -346,27 +346,20 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
var
postageSyncStart
uint64
=
0
if
!
o
.
Standalone
{
postageContractAddress
,
priceOracleAddress
,
startBlock
,
found
:=
listener
.
DiscoverAddresses
(
chainID
)
postageContractAddress
,
startBlock
,
found
:=
listener
.
DiscoverAddresses
(
chainID
)
if
o
.
PostageContractAddress
!=
""
{
if
!
common
.
IsHexAddress
(
o
.
PostageContractAddress
)
{
return
nil
,
errors
.
New
(
"malformed postage stamp address"
)
}
postageContractAddress
=
common
.
HexToAddress
(
o
.
PostageContractAddress
)
}
if
o
.
PriceOracleAddress
!=
""
{
if
!
common
.
IsHexAddress
(
o
.
PriceOracleAddress
)
{
return
nil
,
errors
.
New
(
"malformed price oracle address"
)
}
priceOracleAddress
=
common
.
HexToAddress
(
o
.
PriceOracleAddress
)
}
if
(
o
.
PostageContractAddress
==
""
||
o
.
PriceOracleAddress
==
""
)
&&
!
found
{
}
else
if
!
found
{
return
nil
,
errors
.
New
(
"no known postage stamp addresses for this network"
)
}
if
found
{
postageSyncStart
=
startBlock
}
eventListener
:=
listener
.
New
(
logger
,
swapBackend
,
postageContractAddress
,
priceOracleAddress
,
o
.
BlockTime
)
eventListener
:=
listener
.
New
(
logger
,
swapBackend
,
postageContractAddress
,
o
.
BlockTime
)
b
.
listenerCloser
=
eventListener
batchSvc
=
batchservice
.
New
(
batchStore
,
logger
,
eventListener
)
...
...
pkg/postage/listener/export_test.go
View file @
68e0b591
...
...
@@ -6,7 +6,6 @@ package listener
var
(
PostageStampABI
=
postageStampABI
PriceOracleABI
=
priceOracleABI
BatchCreatedTopic
=
batchCreatedTopic
BatchTopupTopic
=
batchTopupTopic
...
...
pkg/postage/listener/listener.go
View file @
68e0b591
...
...
@@ -30,16 +30,15 @@ const (
)
var
(
postageStampABI
=
parseABI
(
postageabi
.
PostageStampABIv0_1_0
)
priceOracleABI
=
parseABI
(
postageabi
.
PriceOracleABIv0_1_0
)
postageStampABI
=
parseABI
(
postageabi
.
PostageStampABIv0_2_0
)
// batchCreatedTopic is the postage contract's batch created event topic
batchCreatedTopic
=
postageStampABI
.
Events
[
"BatchCreated"
]
.
ID
// batchTopupTopic is the postage contract's batch topup event topic
batchTopupTopic
=
postageStampABI
.
Events
[
"BatchTopUp"
]
.
ID
// batchDepthIncreaseTopic is the postage contract's batch dilution event topic
batchDepthIncreaseTopic
=
postageStampABI
.
Events
[
"BatchDepthIncrease"
]
.
ID
// priceUpdateTopic is the p
rice oracle
's price update event topic
priceUpdateTopic
=
p
riceOracle
ABI
.
Events
[
"PriceUpdate"
]
.
ID
// priceUpdateTopic is the p
ostage contract
's price update event topic
priceUpdateTopic
=
p
ostageStamp
ABI
.
Events
[
"PriceUpdate"
]
.
ID
)
type
BlockHeightContractFilterer
interface
{
...
...
@@ -53,7 +52,6 @@ type listener struct {
blockTime
uint64
postageStampAddress
common
.
Address
priceOracleAddress
common
.
Address
quit
chan
struct
{}
wg
sync
.
WaitGroup
}
...
...
@@ -61,17 +59,14 @@ type listener struct {
func
New
(
logger
logging
.
Logger
,
ev
BlockHeightContractFilterer
,
postageStampAddress
,
priceOracleAddress
common
.
Address
,
postageStampAddress
common
.
Address
,
blockTime
uint64
,
)
postage
.
Listener
{
return
&
listener
{
logger
:
logger
,
ev
:
ev
,
blockTime
:
blockTime
,
postageStampAddress
:
postageStampAddress
,
priceOracleAddress
:
priceOracleAddress
,
quit
:
make
(
chan
struct
{}),
}
}
...
...
@@ -82,7 +77,6 @@ func (l *listener) filterQuery(from, to *big.Int) ethereum.FilterQuery {
ToBlock
:
to
,
Addresses
:
[]
common
.
Address
{
l
.
postageStampAddress
,
l
.
priceOracleAddress
,
},
Topics
:
[][]
common
.
Hash
{
{
...
...
@@ -132,7 +126,7 @@ func (l *listener) processEvent(e types.Log, updater postage.EventUpdater) error
)
case
priceUpdateTopic
:
c
:=
&
priceUpdateEvent
{}
err
:=
transaction
.
ParseEvent
(
&
p
riceOracle
ABI
,
"PriceUpdate"
,
c
,
e
)
err
:=
transaction
.
ParseEvent
(
&
p
ostageStamp
ABI
,
"PriceUpdate"
,
c
,
e
)
if
err
!=
nil
{
return
err
}
...
...
@@ -210,6 +204,11 @@ func (l *listener) Listen(from uint64, updater postage.EventUpdater) <-chan stru
}
}
err
=
updater
.
UpdateBlockNumber
(
to
)
if
err
!=
nil
{
return
err
}
from
=
to
+
1
}
}
...
...
@@ -274,16 +273,15 @@ type priceUpdateEvent struct {
}
var
(
GoerliPostageStampContractAddress
=
common
.
HexToAddress
(
"0xF7a041E7e2B79ccA1975852Eb6D4c6cE52986b4a"
)
GoerliPriceOracleContractAddress
=
common
.
HexToAddress
(
"0x1044534090de6f4014ece6d036C699130Bd5Df43"
)
GoerliStartBlock
=
uint64
(
4247101
)
GoerliPostageStampContractAddress
=
common
.
HexToAddress
(
"0xB3B7f2eD97B735893316aEeA849235de5e8972a2"
)
GoerliStartBlock
=
uint64
(
4818979
)
)
// DiscoverAddresses returns the canonical contracts for this chainID
func
DiscoverAddresses
(
chainID
int64
)
(
postageStamp
,
priceOracle
common
.
Address
,
startBlock
uint64
,
found
bool
)
{
func
DiscoverAddresses
(
chainID
int64
)
(
postageStamp
common
.
Address
,
startBlock
uint64
,
found
bool
)
{
if
chainID
==
5
{
// goerli
return
GoerliPostageStampContractAddress
,
Goerli
PriceOracleContractAddress
,
Goerli
StartBlock
,
true
return
GoerliPostageStampContractAddress
,
GoerliStartBlock
,
true
}
return
common
.
Address
{},
common
.
Address
{},
0
,
false
return
common
.
Address
{},
0
,
false
}
pkg/postage/listener/listener_test.go
View file @
68e0b591
...
...
@@ -23,7 +23,6 @@ var hash common.Hash = common.HexToHash("ff6ec1ed9250a6952fabac07c6eb103550dc651
var
addr
common
.
Address
=
common
.
HexToAddress
(
"abcdef"
)
var
postageStampAddress
common
.
Address
=
common
.
HexToAddress
(
"eeee"
)
var
priceOracleAddress
common
.
Address
=
common
.
HexToAddress
(
"eeef"
)
func
TestListener
(
t
*
testing
.
T
)
{
logger
:=
logging
.
New
(
ioutil
.
Discard
,
0
)
...
...
@@ -46,7 +45,7 @@ func TestListener(t *testing.T) {
c
.
toLog
(
496
),
),
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
priceOracleAddress
,
1
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
1
)
l
.
Listen
(
0
,
ev
)
select
{
...
...
@@ -77,7 +76,7 @@ func TestListener(t *testing.T) {
topup
.
toLog
(
496
),
),
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
priceOracleAddress
,
1
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
1
)
l
.
Listen
(
0
,
ev
)
select
{
...
...
@@ -108,7 +107,7 @@ func TestListener(t *testing.T) {
depthIncrease
.
toLog
(
496
),
),
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
priceOracleAddress
,
1
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
1
)
l
.
Listen
(
0
,
ev
)
select
{
...
...
@@ -137,7 +136,7 @@ func TestListener(t *testing.T) {
priceUpdate
.
toLog
(
496
),
),
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
priceOracleAddress
,
1
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
1
)
l
.
Listen
(
0
,
ev
)
select
{
case
e
:=
<-
evC
:
...
...
@@ -189,7 +188,7 @@ func TestListener(t *testing.T) {
),
WithBlockNumber
(
blockNumber
),
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
priceOracleAddress
,
1
)
l
:=
listener
.
New
(
logger
,
mf
,
postageStampAddress
,
1
)
l
.
Listen
(
0
,
ev
)
select
{
...
...
@@ -243,6 +242,13 @@ func TestListener(t *testing.T) {
case
<-
time
.
After
(
timeout
)
:
t
.
Fatal
(
"timed out waiting for event"
)
}
select
{
case
e
:=
<-
evC
:
e
.
(
blockNumberCall
)
.
compare
(
t
,
blockNumber
-
uint64
(
listener
.
TailSize
))
// event args should be equal
case
<-
time
.
After
(
timeout
)
:
t
.
Fatal
(
"timed out waiting for block number update"
)
}
})
}
...
...
@@ -465,7 +471,7 @@ func (p priceArgs) compare(t *testing.T, want priceArgs) {
}
func
(
p
priceArgs
)
toLog
(
blockNumber
uint64
)
types
.
Log
{
b
,
err
:=
listener
.
P
riceOracle
ABI
.
Events
[
"PriceUpdate"
]
.
Inputs
.
NonIndexed
()
.
Pack
(
p
.
price
)
b
,
err
:=
listener
.
P
ostageStamp
ABI
.
Events
[
"PriceUpdate"
]
.
Inputs
.
NonIndexed
()
.
Pack
(
p
.
price
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
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