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
5a012383
Unverified
Commit
5a012383
authored
May 17, 2021
by
Ralph Pichler
Committed by
GitHub
May 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update default factory and add support for legacy factories (#1539)
parent
54b400eb
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
455 additions
and
269 deletions
+455
-269
cmd.go
cmd/bee/cmd/cmd.go
+46
-44
deploy.go
cmd/bee/cmd/deploy.go
+1
-0
start.go
cmd/bee/cmd/start.go
+37
-36
go.mod
go.mod
+1
-1
go.sum
go.sum
+3
-2
chain.go
pkg/node/chain.go
+24
-7
node.go
pkg/node/node.go
+38
-36
cashout_test.go
pkg/settlement/swap/chequebook/cashout_test.go
+1
-1
chequebook_test.go
pkg/settlement/swap/chequebook/chequebook_test.go
+13
-13
chequestore_test.go
pkg/settlement/swap/chequebook/chequestore_test.go
+18
-18
common_test.go
pkg/settlement/swap/chequebook/common_test.go
+3
-3
factory.go
pkg/settlement/swap/chequebook/factory.go
+72
-21
factory_test.go
pkg/settlement/swap/chequebook/factory_test.go
+177
-83
init.go
pkg/settlement/swap/chequebook/init.go
+8
-1
erc20_test.go
pkg/settlement/swap/erc20/erc20_test.go
+1
-0
transaction.go
pkg/settlement/swap/transaction/mock/transaction.go
+12
-3
No files found.
cmd/bee/cmd/cmd.go
View file @
5a012383
...
@@ -20,49 +20,50 @@ import (
...
@@ -20,49 +20,50 @@ import (
)
)
const
(
const
(
optionNameDataDir
=
"data-dir"
optionNameDataDir
=
"data-dir"
optionNameDBCapacity
=
"db-capacity"
optionNameDBCapacity
=
"db-capacity"
optionNameDBOpenFilesLimit
=
"db-open-files-limit"
optionNameDBOpenFilesLimit
=
"db-open-files-limit"
optionNameDBBlockCacheCapacity
=
"db-block-cache-capacity"
optionNameDBBlockCacheCapacity
=
"db-block-cache-capacity"
optionNameDBWriteBufferSize
=
"db-write-buffer-size"
optionNameDBWriteBufferSize
=
"db-write-buffer-size"
optionNameDBDisableSeeksCompaction
=
"db-disable-seeks-compaction"
optionNameDBDisableSeeksCompaction
=
"db-disable-seeks-compaction"
optionNamePassword
=
"password"
optionNamePassword
=
"password"
optionNamePasswordFile
=
"password-file"
optionNamePasswordFile
=
"password-file"
optionNameAPIAddr
=
"api-addr"
optionNameAPIAddr
=
"api-addr"
optionNameP2PAddr
=
"p2p-addr"
optionNameP2PAddr
=
"p2p-addr"
optionNameNATAddr
=
"nat-addr"
optionNameNATAddr
=
"nat-addr"
optionNameP2PWSEnable
=
"p2p-ws-enable"
optionNameP2PWSEnable
=
"p2p-ws-enable"
optionNameP2PQUICEnable
=
"p2p-quic-enable"
optionNameP2PQUICEnable
=
"p2p-quic-enable"
optionNameDebugAPIEnable
=
"debug-api-enable"
optionNameDebugAPIEnable
=
"debug-api-enable"
optionNameDebugAPIAddr
=
"debug-api-addr"
optionNameDebugAPIAddr
=
"debug-api-addr"
optionNameBootnodes
=
"bootnode"
optionNameBootnodes
=
"bootnode"
optionNameNetworkID
=
"network-id"
optionNameNetworkID
=
"network-id"
optionWelcomeMessage
=
"welcome-message"
optionWelcomeMessage
=
"welcome-message"
optionCORSAllowedOrigins
=
"cors-allowed-origins"
optionCORSAllowedOrigins
=
"cors-allowed-origins"
optionNameStandalone
=
"standalone"
optionNameStandalone
=
"standalone"
optionNameTracingEnabled
=
"tracing-enable"
optionNameTracingEnabled
=
"tracing-enable"
optionNameTracingEndpoint
=
"tracing-endpoint"
optionNameTracingEndpoint
=
"tracing-endpoint"
optionNameTracingServiceName
=
"tracing-service-name"
optionNameTracingServiceName
=
"tracing-service-name"
optionNameVerbosity
=
"verbosity"
optionNameVerbosity
=
"verbosity"
optionNameGlobalPinningEnabled
=
"global-pinning-enable"
optionNameGlobalPinningEnabled
=
"global-pinning-enable"
optionNamePaymentThreshold
=
"payment-threshold"
optionNamePaymentThreshold
=
"payment-threshold"
optionNamePaymentTolerance
=
"payment-tolerance"
optionNamePaymentTolerance
=
"payment-tolerance"
optionNamePaymentEarly
=
"payment-early"
optionNamePaymentEarly
=
"payment-early"
optionNameResolverEndpoints
=
"resolver-options"
optionNameResolverEndpoints
=
"resolver-options"
optionNameBootnodeMode
=
"bootnode-mode"
optionNameBootnodeMode
=
"bootnode-mode"
optionNameGatewayMode
=
"gateway-mode"
optionNameGatewayMode
=
"gateway-mode"
optionNameClefSignerEnable
=
"clef-signer-enable"
optionNameClefSignerEnable
=
"clef-signer-enable"
optionNameClefSignerEndpoint
=
"clef-signer-endpoint"
optionNameClefSignerEndpoint
=
"clef-signer-endpoint"
optionNameClefSignerEthereumAddress
=
"clef-signer-ethereum-address"
optionNameClefSignerEthereumAddress
=
"clef-signer-ethereum-address"
optionNameSwapEndpoint
=
"swap-endpoint"
optionNameSwapEndpoint
=
"swap-endpoint"
optionNameSwapFactoryAddress
=
"swap-factory-address"
optionNameSwapFactoryAddress
=
"swap-factory-address"
optionNameSwapInitialDeposit
=
"swap-initial-deposit"
optionNameSwapLegacyFactoryAddresses
=
"swap-legacy-factory-addresses"
optionNameSwapEnable
=
"swap-enable"
optionNameSwapInitialDeposit
=
"swap-initial-deposit"
optionNameTransactionHash
=
"transaction"
optionNameSwapEnable
=
"swap-enable"
optionNameFullNode
=
"full-node"
optionNameTransactionHash
=
"transaction"
optionNamePostageContractAddress
=
"postage-stamp-address"
optionNameFullNode
=
"full-node"
optionNamePriceOracleAddress
=
"price-oracle-address"
optionNamePostageContractAddress
=
"postage-stamp-address"
optionNameBlockTime
=
"block-time"
optionNamePriceOracleAddress
=
"price-oracle-address"
optionNameBlockTime
=
"block-time"
)
)
func
init
()
{
func
init
()
{
...
@@ -226,7 +227,8 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
...
@@ -226,7 +227,8 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
String
(
optionNameClefSignerEndpoint
,
""
,
"clef signer endpoint"
)
cmd
.
Flags
()
.
String
(
optionNameClefSignerEndpoint
,
""
,
"clef signer endpoint"
)
cmd
.
Flags
()
.
String
(
optionNameClefSignerEthereumAddress
,
""
,
"ethereum address to use from clef signer"
)
cmd
.
Flags
()
.
String
(
optionNameClefSignerEthereumAddress
,
""
,
"ethereum address to use from clef signer"
)
cmd
.
Flags
()
.
String
(
optionNameSwapEndpoint
,
"http://localhost:8545"
,
"swap ethereum blockchain endpoint"
)
cmd
.
Flags
()
.
String
(
optionNameSwapEndpoint
,
"http://localhost:8545"
,
"swap ethereum blockchain endpoint"
)
cmd
.
Flags
()
.
String
(
optionNameSwapFactoryAddress
,
""
,
"swap factory address"
)
cmd
.
Flags
()
.
String
(
optionNameSwapFactoryAddress
,
""
,
"swap factory addresses"
)
cmd
.
Flags
()
.
StringSlice
(
optionNameSwapLegacyFactoryAddresses
,
nil
,
"legacy swap factory addresses"
)
cmd
.
Flags
()
.
String
(
optionNameSwapInitialDeposit
,
"100000000000000000"
,
"initial deposit if deploying a new chequebook"
)
cmd
.
Flags
()
.
String
(
optionNameSwapInitialDeposit
,
"100000000000000000"
,
"initial deposit if deploying a new chequebook"
)
cmd
.
Flags
()
.
Bool
(
optionNameSwapEnable
,
true
,
"enable swap"
)
cmd
.
Flags
()
.
Bool
(
optionNameSwapEnable
,
true
,
"enable swap"
)
cmd
.
Flags
()
.
Bool
(
optionNameFullNode
,
false
,
"cause the node to start in full mode"
)
cmd
.
Flags
()
.
Bool
(
optionNameFullNode
,
false
,
"cause the node to start in full mode"
)
...
...
cmd/bee/cmd/deploy.go
View file @
5a012383
...
@@ -74,6 +74,7 @@ func (c *command) initDeployCmd() error {
...
@@ -74,6 +74,7 @@ func (c *command) initDeployCmd() error {
chainID
,
chainID
,
transactionService
,
transactionService
,
factoryAddress
,
factoryAddress
,
nil
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
cmd/bee/cmd/start.go
View file @
5a012383
...
@@ -116,42 +116,43 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
...
@@ -116,42 +116,43 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
}
}
b
,
err
:=
node
.
NewBee
(
c
.
config
.
GetString
(
optionNameP2PAddr
),
signerConfig
.
address
,
*
signerConfig
.
publicKey
,
signerConfig
.
signer
,
c
.
config
.
GetUint64
(
optionNameNetworkID
),
logger
,
signerConfig
.
libp2pPrivateKey
,
signerConfig
.
pssPrivateKey
,
node
.
Options
{
b
,
err
:=
node
.
NewBee
(
c
.
config
.
GetString
(
optionNameP2PAddr
),
signerConfig
.
address
,
*
signerConfig
.
publicKey
,
signerConfig
.
signer
,
c
.
config
.
GetUint64
(
optionNameNetworkID
),
logger
,
signerConfig
.
libp2pPrivateKey
,
signerConfig
.
pssPrivateKey
,
node
.
Options
{
DataDir
:
c
.
config
.
GetString
(
optionNameDataDir
),
DataDir
:
c
.
config
.
GetString
(
optionNameDataDir
),
DBCapacity
:
c
.
config
.
GetUint64
(
optionNameDBCapacity
),
DBCapacity
:
c
.
config
.
GetUint64
(
optionNameDBCapacity
),
DBOpenFilesLimit
:
c
.
config
.
GetUint64
(
optionNameDBOpenFilesLimit
),
DBOpenFilesLimit
:
c
.
config
.
GetUint64
(
optionNameDBOpenFilesLimit
),
DBBlockCacheCapacity
:
c
.
config
.
GetUint64
(
optionNameDBBlockCacheCapacity
),
DBBlockCacheCapacity
:
c
.
config
.
GetUint64
(
optionNameDBBlockCacheCapacity
),
DBWriteBufferSize
:
c
.
config
.
GetUint64
(
optionNameDBWriteBufferSize
),
DBWriteBufferSize
:
c
.
config
.
GetUint64
(
optionNameDBWriteBufferSize
),
DBDisableSeeksCompaction
:
c
.
config
.
GetBool
(
optionNameDBDisableSeeksCompaction
),
DBDisableSeeksCompaction
:
c
.
config
.
GetBool
(
optionNameDBDisableSeeksCompaction
),
APIAddr
:
c
.
config
.
GetString
(
optionNameAPIAddr
),
APIAddr
:
c
.
config
.
GetString
(
optionNameAPIAddr
),
DebugAPIAddr
:
debugAPIAddr
,
DebugAPIAddr
:
debugAPIAddr
,
Addr
:
c
.
config
.
GetString
(
optionNameP2PAddr
),
Addr
:
c
.
config
.
GetString
(
optionNameP2PAddr
),
NATAddr
:
c
.
config
.
GetString
(
optionNameNATAddr
),
NATAddr
:
c
.
config
.
GetString
(
optionNameNATAddr
),
EnableWS
:
c
.
config
.
GetBool
(
optionNameP2PWSEnable
),
EnableWS
:
c
.
config
.
GetBool
(
optionNameP2PWSEnable
),
EnableQUIC
:
c
.
config
.
GetBool
(
optionNameP2PQUICEnable
),
EnableQUIC
:
c
.
config
.
GetBool
(
optionNameP2PQUICEnable
),
WelcomeMessage
:
c
.
config
.
GetString
(
optionWelcomeMessage
),
WelcomeMessage
:
c
.
config
.
GetString
(
optionWelcomeMessage
),
Bootnodes
:
c
.
config
.
GetStringSlice
(
optionNameBootnodes
),
Bootnodes
:
c
.
config
.
GetStringSlice
(
optionNameBootnodes
),
CORSAllowedOrigins
:
c
.
config
.
GetStringSlice
(
optionCORSAllowedOrigins
),
CORSAllowedOrigins
:
c
.
config
.
GetStringSlice
(
optionCORSAllowedOrigins
),
Standalone
:
c
.
config
.
GetBool
(
optionNameStandalone
),
Standalone
:
c
.
config
.
GetBool
(
optionNameStandalone
),
TracingEnabled
:
c
.
config
.
GetBool
(
optionNameTracingEnabled
),
TracingEnabled
:
c
.
config
.
GetBool
(
optionNameTracingEnabled
),
TracingEndpoint
:
c
.
config
.
GetString
(
optionNameTracingEndpoint
),
TracingEndpoint
:
c
.
config
.
GetString
(
optionNameTracingEndpoint
),
TracingServiceName
:
c
.
config
.
GetString
(
optionNameTracingServiceName
),
TracingServiceName
:
c
.
config
.
GetString
(
optionNameTracingServiceName
),
Logger
:
logger
,
Logger
:
logger
,
GlobalPinningEnabled
:
c
.
config
.
GetBool
(
optionNameGlobalPinningEnabled
),
GlobalPinningEnabled
:
c
.
config
.
GetBool
(
optionNameGlobalPinningEnabled
),
PaymentThreshold
:
c
.
config
.
GetString
(
optionNamePaymentThreshold
),
PaymentThreshold
:
c
.
config
.
GetString
(
optionNamePaymentThreshold
),
PaymentTolerance
:
c
.
config
.
GetString
(
optionNamePaymentTolerance
),
PaymentTolerance
:
c
.
config
.
GetString
(
optionNamePaymentTolerance
),
PaymentEarly
:
c
.
config
.
GetString
(
optionNamePaymentEarly
),
PaymentEarly
:
c
.
config
.
GetString
(
optionNamePaymentEarly
),
ResolverConnectionCfgs
:
resolverCfgs
,
ResolverConnectionCfgs
:
resolverCfgs
,
GatewayMode
:
c
.
config
.
GetBool
(
optionNameGatewayMode
),
GatewayMode
:
c
.
config
.
GetBool
(
optionNameGatewayMode
),
BootnodeMode
:
bootNode
,
BootnodeMode
:
bootNode
,
SwapEndpoint
:
c
.
config
.
GetString
(
optionNameSwapEndpoint
),
SwapEndpoint
:
c
.
config
.
GetString
(
optionNameSwapEndpoint
),
SwapFactoryAddress
:
c
.
config
.
GetString
(
optionNameSwapFactoryAddress
),
SwapFactoryAddress
:
c
.
config
.
GetString
(
optionNameSwapFactoryAddress
),
SwapInitialDeposit
:
c
.
config
.
GetString
(
optionNameSwapInitialDeposit
),
SwapLegacyFactoryAddresses
:
c
.
config
.
GetStringSlice
(
optionNameSwapLegacyFactoryAddresses
),
SwapEnable
:
c
.
config
.
GetBool
(
optionNameSwapEnable
),
SwapInitialDeposit
:
c
.
config
.
GetString
(
optionNameSwapInitialDeposit
),
FullNodeMode
:
fullNode
,
SwapEnable
:
c
.
config
.
GetBool
(
optionNameSwapEnable
),
Transaction
:
c
.
config
.
GetString
(
optionNameTransactionHash
),
FullNodeMode
:
fullNode
,
PostageContractAddress
:
c
.
config
.
GetString
(
optionNamePostageContractAddress
),
Transaction
:
c
.
config
.
GetString
(
optionNameTransactionHash
),
PriceOracleAddress
:
c
.
config
.
GetString
(
optionNamePriceOracleAddress
),
PostageContractAddress
:
c
.
config
.
GetString
(
optionNamePostageContractAddress
),
BlockTime
:
c
.
config
.
GetUint64
(
optionNameBlockTime
),
PriceOracleAddress
:
c
.
config
.
GetString
(
optionNamePriceOracleAddress
),
BlockTime
:
c
.
config
.
GetUint64
(
optionNameBlockTime
),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
go.mod
View file @
5a012383
...
@@ -9,7 +9,7 @@ require (
...
@@ -9,7 +9,7 @@ require (
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/ethereum/go-ethereum v1.9.23
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.1.0
github.com/ethersphere/go-sw3-abi v0.
3.2
github.com/ethersphere/go-sw3-abi v0.
4.0
github.com/ethersphere/langos v1.0.0
github.com/ethersphere/langos v1.0.0
github.com/gogo/protobuf v1.3.1
github.com/gogo/protobuf v1.3.1
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
...
...
go.sum
View file @
5a012383
...
@@ -143,6 +143,7 @@ github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUn
...
@@ -143,6 +143,7 @@ github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUn
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf h1:sh8rkQZavChcmakYiSlqu2425CHyFXLZZnvm7PDpU8M=
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
...
@@ -161,8 +162,8 @@ github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0Id
...
@@ -161,8 +162,8 @@ github.com/ethereum/go-ethereum v1.9.23 h1:SIKhg/z4Q7AbvqcxuPYvMxf36che/Rq/Pp0Id
github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
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 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.1.0/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.
3.2 h1:BVTuSZ9Ph/JJBglU9pCRSch3gDq4g5QEto6KzMYP/08
=
github.com/ethersphere/go-sw3-abi v0.
4.0 h1:T3ANY+ktWrPAwe2U0tZi+DILpkHzto5ym/XwV/Bbz8g
=
github.com/ethersphere/go-sw3-abi v0.
3.2
/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/go-sw3-abi v0.
4.0
/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
github.com/ethersphere/langos v1.0.0/go.mod h1:dlcN2j4O8sQ+BlCaxeBu43bgr4RQ+inJ+pHwLeZg5Tw=
github.com/ethersphere/langos v1.0.0/go.mod h1:dlcN2j4O8sQ+BlCaxeBu43bgr4RQ+inJ+pHwLeZg5Tw=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
...
...
pkg/node/chain.go
View file @
5a012383
...
@@ -86,26 +86,43 @@ func InitChequebookFactory(
...
@@ -86,26 +86,43 @@ func InitChequebookFactory(
chainID
int64
,
chainID
int64
,
transactionService
transaction
.
Service
,
transactionService
transaction
.
Service
,
factoryAddress
string
,
factoryAddress
string
,
legacyFactoryAddresses
[]
string
,
)
(
chequebook
.
Factory
,
error
)
{
)
(
chequebook
.
Factory
,
error
)
{
var
addr
common
.
Address
var
currentFactory
common
.
Address
var
legacyFactories
[]
common
.
Address
foundFactory
,
foundLegacyFactories
,
found
:=
chequebook
.
DiscoverFactoryAddress
(
chainID
)
if
factoryAddress
==
""
{
if
factoryAddress
==
""
{
var
found
bool
addr
,
found
=
chequebook
.
DiscoverFactoryAddress
(
chainID
)
if
!
found
{
if
!
found
{
return
nil
,
errors
.
New
(
"no known factory address for this network"
)
return
nil
,
errors
.
New
(
"no known factory address for this network"
)
}
}
logger
.
Infof
(
"using default factory address for chain id %d: %x"
,
chainID
,
addr
)
currentFactory
=
foundFactory
logger
.
Infof
(
"using default factory address for chain id %d: %x"
,
chainID
,
currentFactory
)
}
else
if
!
common
.
IsHexAddress
(
factoryAddress
)
{
}
else
if
!
common
.
IsHexAddress
(
factoryAddress
)
{
return
nil
,
errors
.
New
(
"malformed factory address"
)
return
nil
,
errors
.
New
(
"malformed factory address"
)
}
else
{
}
else
{
addr
=
common
.
HexToAddress
(
factoryAddress
)
currentFactory
=
common
.
HexToAddress
(
factoryAddress
)
logger
.
Infof
(
"using custom factory address: %x"
,
addr
)
logger
.
Infof
(
"using custom factory address: %x"
,
currentFactory
)
}
if
legacyFactoryAddresses
==
nil
{
if
found
{
legacyFactories
=
foundLegacyFactories
}
}
else
{
for
_
,
legacyAddress
:=
range
legacyFactoryAddresses
{
if
!
common
.
IsHexAddress
(
legacyAddress
)
{
return
nil
,
errors
.
New
(
"malformed factory address"
)
}
legacyFactories
=
append
(
legacyFactories
,
common
.
HexToAddress
(
legacyAddress
))
}
}
}
return
chequebook
.
NewFactory
(
return
chequebook
.
NewFactory
(
backend
,
backend
,
transactionService
,
transactionService
,
addr
,
currentFactory
,
legacyFactories
,
),
nil
),
nil
}
}
...
...
pkg/node/node.go
View file @
5a012383
...
@@ -97,42 +97,43 @@ type Bee struct {
...
@@ -97,42 +97,43 @@ type Bee struct {
}
}
type
Options
struct
{
type
Options
struct
{
DataDir
string
DataDir
string
DBCapacity
uint64
DBCapacity
uint64
DBOpenFilesLimit
uint64
DBOpenFilesLimit
uint64
DBWriteBufferSize
uint64
DBWriteBufferSize
uint64
DBBlockCacheCapacity
uint64
DBBlockCacheCapacity
uint64
DBDisableSeeksCompaction
bool
DBDisableSeeksCompaction
bool
APIAddr
string
APIAddr
string
DebugAPIAddr
string
DebugAPIAddr
string
Addr
string
Addr
string
NATAddr
string
NATAddr
string
EnableWS
bool
EnableWS
bool
EnableQUIC
bool
EnableQUIC
bool
WelcomeMessage
string
WelcomeMessage
string
Bootnodes
[]
string
Bootnodes
[]
string
CORSAllowedOrigins
[]
string
CORSAllowedOrigins
[]
string
Logger
logging
.
Logger
Logger
logging
.
Logger
Standalone
bool
Standalone
bool
TracingEnabled
bool
TracingEnabled
bool
TracingEndpoint
string
TracingEndpoint
string
TracingServiceName
string
TracingServiceName
string
GlobalPinningEnabled
bool
GlobalPinningEnabled
bool
PaymentThreshold
string
PaymentThreshold
string
PaymentTolerance
string
PaymentTolerance
string
PaymentEarly
string
PaymentEarly
string
ResolverConnectionCfgs
[]
multiresolver
.
ConnectionConfig
ResolverConnectionCfgs
[]
multiresolver
.
ConnectionConfig
GatewayMode
bool
GatewayMode
bool
BootnodeMode
bool
BootnodeMode
bool
SwapEndpoint
string
SwapEndpoint
string
SwapFactoryAddress
string
SwapFactoryAddress
string
SwapInitialDeposit
string
SwapLegacyFactoryAddresses
[]
string
SwapEnable
bool
SwapInitialDeposit
string
FullNodeMode
bool
SwapEnable
bool
Transaction
string
FullNodeMode
bool
PostageContractAddress
string
Transaction
string
PriceOracleAddress
string
PostageContractAddress
string
BlockTime
uint64
PriceOracleAddress
string
BlockTime
uint64
}
}
func
NewBee
(
addr
string
,
swarmAddress
swarm
.
Address
,
publicKey
ecdsa
.
PublicKey
,
signer
crypto
.
Signer
,
networkID
uint64
,
logger
logging
.
Logger
,
libp2pPrivateKey
,
pssPrivateKey
*
ecdsa
.
PrivateKey
,
o
Options
)
(
b
*
Bee
,
err
error
)
{
func
NewBee
(
addr
string
,
swarmAddress
swarm
.
Address
,
publicKey
ecdsa
.
PublicKey
,
signer
crypto
.
Signer
,
networkID
uint64
,
logger
logging
.
Logger
,
libp2pPrivateKey
,
pssPrivateKey
*
ecdsa
.
PrivateKey
,
o
Options
)
(
b
*
Bee
,
err
error
)
{
...
@@ -241,6 +242,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
...
@@ -241,6 +242,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
chainID
,
chainID
,
transactionService
,
transactionService
,
o
.
SwapFactoryAddress
,
o
.
SwapFactoryAddress
,
o
.
SwapLegacyFactoryAddresses
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/settlement/swap/chequebook/cashout_test.go
View file @
5a012383
...
@@ -256,7 +256,7 @@ func TestCashoutStatusReverted(t *testing.T) {
...
@@ -256,7 +256,7 @@ func TestCashoutStatusReverted(t *testing.T) {
),
),
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABISend
(
&
chequebookABI
,
txHash
,
chequebookAddress
,
big
.
NewInt
(
0
),
"cashChequeBeneficiary"
,
recipientAddress
,
cheque
.
CumulativePayout
,
cheque
.
Signature
),
transactionmock
.
WithABISend
(
&
chequebookABI
,
txHash
,
chequebookAddress
,
big
.
NewInt
(
0
),
"cashChequeBeneficiary"
,
recipientAddress
,
cheque
.
CumulativePayout
,
cheque
.
Signature
),
transactionmock
.
WithABICall
(
&
chequebookABI
,
onChainPaidOut
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
WithABICall
(
&
chequebookABI
,
chequebookAddress
,
onChainPaidOut
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
),
),
chequestoremock
.
NewChequeStore
(
chequestoremock
.
NewChequeStore
(
chequestoremock
.
WithLastChequeFunc
(
func
(
c
common
.
Address
)
(
*
chequebook
.
SignedCheque
,
error
)
{
chequestoremock
.
WithLastChequeFunc
(
func
(
c
common
.
Address
)
(
*
chequebook
.
SignedCheque
,
error
)
{
...
...
pkg/settlement/swap/chequebook/chequebook_test.go
View file @
5a012383
...
@@ -46,7 +46,7 @@ func TestChequebookBalance(t *testing.T) {
...
@@ -46,7 +46,7 @@ func TestChequebookBalance(t *testing.T) {
balance
:=
big
.
NewInt
(
10
)
balance
:=
big
.
NewInt
(
10
)
chequebookService
,
err
:=
chequebook
.
New
(
chequebookService
,
err
:=
chequebook
.
New
(
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICall
(
&
chequebookABI
,
balance
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
WithABICall
(
&
chequebookABI
,
address
,
balance
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
),
),
address
,
address
,
ownerAdress
,
ownerAdress
,
...
@@ -191,12 +191,12 @@ func TestChequebookIssue(t *testing.T) {
...
@@ -191,12 +191,12 @@ func TestChequebookIssue(t *testing.T) {
chequebookService
,
err
:=
chequebook
.
New
(
chequebookService
,
err
:=
chequebook
.
New
(
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
100
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
100
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
100
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
100
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
100
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
100
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
),
),
),
),
address
,
address
,
...
@@ -377,8 +377,8 @@ func TestChequebookIssueOutOfFunds(t *testing.T) {
...
@@ -377,8 +377,8 @@ func TestChequebookIssueOutOfFunds(t *testing.T) {
chequebookService
,
err
:=
chequebook
.
New
(
chequebookService
,
err
:=
chequebook
.
New
(
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
),
),
),
),
address
,
address
,
...
@@ -416,8 +416,8 @@ func TestChequebookWithdraw(t *testing.T) {
...
@@ -416,8 +416,8 @@ func TestChequebookWithdraw(t *testing.T) {
chequebookService
,
err
:=
chequebook
.
New
(
chequebookService
,
err
:=
chequebook
.
New
(
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
balance
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
balance
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
),
),
transactionmock
.
WithABISend
(
&
chequebookABI
,
txHash
,
address
,
big
.
NewInt
(
0
),
"withdraw"
,
withdrawAmount
),
transactionmock
.
WithABISend
(
&
chequebookABI
,
txHash
,
address
,
big
.
NewInt
(
0
),
"withdraw"
,
withdrawAmount
),
),
),
...
@@ -451,8 +451,8 @@ func TestChequebookWithdrawInsufficientFunds(t *testing.T) {
...
@@ -451,8 +451,8 @@ func TestChequebookWithdrawInsufficientFunds(t *testing.T) {
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABISend
(
&
chequebookABI
,
txHash
,
address
,
big
.
NewInt
(
0
),
"withdraw"
,
withdrawAmount
),
transactionmock
.
WithABISend
(
&
chequebookABI
,
txHash
,
address
,
big
.
NewInt
(
0
),
"withdraw"
,
withdrawAmount
),
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
address
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"totalPaidOut"
),
),
),
),
),
address
,
address
,
...
...
pkg/settlement/swap/chequebook/chequestore_test.go
View file @
5a012383
...
@@ -53,12 +53,12 @@ func TestReceiveCheque(t *testing.T) {
...
@@ -53,12 +53,12 @@ func TestReceiveCheque(t *testing.T) {
beneficiary
,
beneficiary
,
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
cumulativePayout2
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
c
hequebookAddress
,
c
umulativePayout2
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
cumulativePayout2
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
c
hequebookAddress
,
c
umulativePayout2
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
),
),
),
),
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -175,9 +175,9 @@ func TestReceiveChequeInvalidAmount(t *testing.T) {
...
@@ -175,9 +175,9 @@ func TestReceiveChequeInvalidAmount(t *testing.T) {
beneficiary
,
beneficiary
,
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
cumulativePayout
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
c
hequebookAddress
,
c
umulativePayout
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
),
),
),
),
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -232,8 +232,8 @@ func TestReceiveChequeInvalidChequebook(t *testing.T) {
...
@@ -232,8 +232,8 @@ func TestReceiveChequeInvalidChequebook(t *testing.T) {
beneficiary
,
beneficiary
,
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
cumulativePayout
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
c
hequebookAddress
,
c
umulativePayout
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
),
),
),
),
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -273,7 +273,7 @@ func TestReceiveChequeInvalidSignature(t *testing.T) {
...
@@ -273,7 +273,7 @@ func TestReceiveChequeInvalidSignature(t *testing.T) {
beneficiary
,
beneficiary
,
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
),
),
),
),
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -313,9 +313,9 @@ func TestReceiveChequeInsufficientBalance(t *testing.T) {
...
@@ -313,9 +313,9 @@ func TestReceiveChequeInsufficientBalance(t *testing.T) {
beneficiary
,
beneficiary
,
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
new
(
big
.
Int
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
1
))
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
new
(
big
.
Int
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
1
))
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
),
),
),
),
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -355,9 +355,9 @@ func TestReceiveChequeSufficientBalancePaidOut(t *testing.T) {
...
@@ -355,9 +355,9 @@ func TestReceiveChequeSufficientBalancePaidOut(t *testing.T) {
beneficiary
,
beneficiary
,
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
WithABICallSequence
(
transactionmock
.
ABICall
(
&
chequebookABI
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
issuer
.
Hash
()
.
Bytes
(),
"issuer"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
new
(
big
.
Int
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
100
))
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
new
(
big
.
Int
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
100
))
.
FillBytes
(
make
([]
byte
,
32
)),
"balance"
),
transactionmock
.
ABICall
(
&
chequebookABI
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
transactionmock
.
ABICall
(
&
chequebookABI
,
chequebookAddress
,
big
.
NewInt
(
0
)
.
FillBytes
(
make
([]
byte
,
32
)),
"paidOut"
,
beneficiary
),
),
),
),
),
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
...
pkg/settlement/swap/chequebook/common_test.go
View file @
5a012383
...
@@ -22,7 +22,7 @@ func (m *chequeSignerMock) Sign(cheque *chequebook.Cheque) ([]byte, error) {
...
@@ -22,7 +22,7 @@ func (m *chequeSignerMock) Sign(cheque *chequebook.Cheque) ([]byte, error) {
type
factoryMock
struct
{
type
factoryMock
struct
{
erc20Address
func
(
ctx
context
.
Context
)
(
common
.
Address
,
error
)
erc20Address
func
(
ctx
context
.
Context
)
(
common
.
Address
,
error
)
deploy
func
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
deploy
func
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
,
nonce
common
.
Hash
)
(
common
.
Hash
,
error
)
waitDeployed
func
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
waitDeployed
func
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
verifyBytecode
func
(
ctx
context
.
Context
)
error
verifyBytecode
func
(
ctx
context
.
Context
)
error
verifyChequebook
func
(
ctx
context
.
Context
,
chequebook
common
.
Address
)
error
verifyChequebook
func
(
ctx
context
.
Context
,
chequebook
common
.
Address
)
error
...
@@ -33,8 +33,8 @@ func (m *factoryMock) ERC20Address(ctx context.Context) (common.Address, error)
...
@@ -33,8 +33,8 @@ func (m *factoryMock) ERC20Address(ctx context.Context) (common.Address, error)
return
m
.
erc20Address
(
ctx
)
return
m
.
erc20Address
(
ctx
)
}
}
func
(
m
*
factoryMock
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
{
func
(
m
*
factoryMock
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
,
nonce
common
.
Hash
)
(
common
.
Hash
,
error
)
{
return
m
.
deploy
(
ctx
,
issuer
,
defaultHardDepositTimeoutDuration
)
return
m
.
deploy
(
ctx
,
issuer
,
defaultHardDepositTimeoutDuration
,
nonce
)
}
}
func
(
m
*
factoryMock
)
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
{
func
(
m
*
factoryMock
)
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
{
...
...
pkg/settlement/swap/chequebook/factory.go
View file @
5a012383
...
@@ -22,7 +22,7 @@ var (
...
@@ -22,7 +22,7 @@ var (
ErrNotDeployedByFactory
=
errors
.
New
(
"chequebook not deployed by factory"
)
ErrNotDeployedByFactory
=
errors
.
New
(
"chequebook not deployed by factory"
)
errDecodeABI
=
errors
.
New
(
"could not decode abi data"
)
errDecodeABI
=
errors
.
New
(
"could not decode abi data"
)
factoryABI
=
transaction
.
ParseABIUnchecked
(
sw3abi
.
SimpleSwapFactoryABIv0_
3_1
)
factoryABI
=
transaction
.
ParseABIUnchecked
(
sw3abi
.
SimpleSwapFactoryABIv0_
4_0
)
simpleSwapDeployedEventType
=
factoryABI
.
Events
[
"SimpleSwapDeployed"
]
simpleSwapDeployedEventType
=
factoryABI
.
Events
[
"SimpleSwapDeployed"
]
)
)
...
@@ -31,7 +31,7 @@ type Factory interface {
...
@@ -31,7 +31,7 @@ type Factory interface {
// ERC20Address returns the token for which this factory deploys chequebooks.
// ERC20Address returns the token for which this factory deploys chequebooks.
ERC20Address
(
ctx
context
.
Context
)
(
common
.
Address
,
error
)
ERC20Address
(
ctx
context
.
Context
)
(
common
.
Address
,
error
)
// Deploy deploys a new chequebook and returns once the transaction has been submitted.
// Deploy deploys a new chequebook and returns once the transaction has been submitted.
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
,
nonce
common
.
Hash
)
(
common
.
Hash
,
error
)
// WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address
// WaitDeployed waits for the deployment transaction to confirm and returns the chequebook address
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
WaitDeployed
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
common
.
Address
,
error
)
// VerifyBytecode checks that the factory is valid.
// VerifyBytecode checks that the factory is valid.
...
@@ -43,25 +43,36 @@ type Factory interface {
...
@@ -43,25 +43,36 @@ type Factory interface {
type
factory
struct
{
type
factory
struct
{
backend
transaction
.
Backend
backend
transaction
.
Backend
transactionService
transaction
.
Service
transactionService
transaction
.
Service
address
common
.
Address
address
common
.
Address
// address of the factory to use for deployments
legacyAddresses
[]
common
.
Address
// addresses of old factories which were allowed for deployment
}
}
type
simpleSwapDeployedEvent
struct
{
type
simpleSwapDeployedEvent
struct
{
ContractAddress
common
.
Address
ContractAddress
common
.
Address
}
}
// the bytecode of factories which can be used for deployment
var
currentDeployVersion
[]
byte
=
common
.
FromHex
(
sw3abi
.
SimpleSwapFactoryDeployedBinv0_4_0
)
// the bytecode of factories from which we accept chequebooks
var
supportedVersions
=
[][]
byte
{
currentDeployVersion
,
common
.
FromHex
(
sw3abi
.
SimpleSwapFactoryDeployedBinv0_3_1
),
}
// NewFactory creates a new factory service for the provided factory contract.
// NewFactory creates a new factory service for the provided factory contract.
func
NewFactory
(
backend
transaction
.
Backend
,
transactionService
transaction
.
Service
,
address
common
.
Address
)
Factory
{
func
NewFactory
(
backend
transaction
.
Backend
,
transactionService
transaction
.
Service
,
address
common
.
Address
,
legacyAddresses
[]
common
.
Address
)
Factory
{
return
&
factory
{
return
&
factory
{
backend
:
backend
,
backend
:
backend
,
transactionService
:
transactionService
,
transactionService
:
transactionService
,
address
:
address
,
address
:
address
,
legacyAddresses
:
legacyAddresses
,
}
}
}
}
// Deploy deploys a new chequebook and returns once the transaction has been submitted.
// Deploy deploys a new chequebook and returns once the transaction has been submitted.
func
(
c
*
factory
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
)
(
common
.
Hash
,
error
)
{
func
(
c
*
factory
)
Deploy
(
ctx
context
.
Context
,
issuer
common
.
Address
,
defaultHardDepositTimeoutDuration
*
big
.
Int
,
nonce
common
.
Hash
)
(
common
.
Hash
,
error
)
{
callData
,
err
:=
factoryABI
.
Pack
(
"deploySimpleSwap"
,
issuer
,
big
.
NewInt
(
0
)
.
Set
(
defaultHardDepositTimeoutDuration
))
callData
,
err
:=
factoryABI
.
Pack
(
"deploySimpleSwap"
,
issuer
,
big
.
NewInt
(
0
)
.
Set
(
defaultHardDepositTimeoutDuration
)
,
nonce
)
if
err
!=
nil
{
if
err
!=
nil
{
return
common
.
Hash
{},
err
return
common
.
Hash
{},
err
}
}
...
@@ -105,45 +116,83 @@ func (c *factory) VerifyBytecode(ctx context.Context) (err error) {
...
@@ -105,45 +116,83 @@ func (c *factory) VerifyBytecode(ctx context.Context) (err error) {
return
err
return
err
}
}
referenceCode
:=
common
.
FromHex
(
sw3abi
.
SimpleSwapFactoryDeployedBinv0_3_1
)
if
!
bytes
.
Equal
(
code
,
currentDeployVersion
)
{
if
!
bytes
.
Equal
(
code
,
referenceCode
)
{
return
ErrInvalidFactory
return
ErrInvalidFactory
}
}
LOOP
:
for
_
,
factoryAddress
:=
range
c
.
legacyAddresses
{
code
,
err
:=
c
.
backend
.
CodeAt
(
ctx
,
factoryAddress
,
nil
)
if
err
!=
nil
{
return
err
}
for
_
,
referenceCode
:=
range
supportedVersions
{
if
bytes
.
Equal
(
code
,
referenceCode
)
{
continue
LOOP
}
}
return
fmt
.
Errorf
(
"failed to find matching bytecode for factory %x: %w"
,
factoryAddress
,
ErrInvalidFactory
)
}
return
nil
return
nil
}
}
// VerifyChequebook checks that the supplied chequebook has been deployed by this factory.
func
(
c
*
factory
)
verifyChequebookAgainstFactory
(
ctx
context
.
Context
,
factory
common
.
Address
,
chequebook
common
.
Address
)
(
bool
,
error
)
{
func
(
c
*
factory
)
VerifyChequebook
(
ctx
context
.
Context
,
chequebook
common
.
Address
)
error
{
callData
,
err
:=
factoryABI
.
Pack
(
"deployedContracts"
,
chequebook
)
callData
,
err
:=
factoryABI
.
Pack
(
"deployedContracts"
,
chequebook
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
false
,
err
}
}
output
,
err
:=
c
.
transactionService
.
Call
(
ctx
,
&
transaction
.
TxRequest
{
output
,
err
:=
c
.
transactionService
.
Call
(
ctx
,
&
transaction
.
TxRequest
{
To
:
&
c
.
address
,
To
:
&
factory
,
Data
:
callData
,
Data
:
callData
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
false
,
err
}
}
results
,
err
:=
factoryABI
.
Unpack
(
"deployedContracts"
,
output
)
results
,
err
:=
factoryABI
.
Unpack
(
"deployedContracts"
,
output
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
false
,
err
}
}
if
len
(
results
)
!=
1
{
if
len
(
results
)
!=
1
{
return
errDecodeABI
return
false
,
errDecodeABI
}
}
deployed
,
ok
:=
abi
.
ConvertType
(
results
[
0
],
new
(
bool
))
.
(
*
bool
)
deployed
,
ok
:=
abi
.
ConvertType
(
results
[
0
],
new
(
bool
))
.
(
*
bool
)
if
!
ok
||
deployed
==
nil
{
if
!
ok
||
deployed
==
nil
{
return
errDecodeABI
return
false
,
errDecodeABI
}
}
if
!*
deployed
{
if
!*
deployed
{
return
ErrNotDeployedByFactory
return
false
,
nil
}
}
return
nil
return
true
,
nil
}
// VerifyChequebook checks that the supplied chequebook has been deployed by a supported factory.
func
(
c
*
factory
)
VerifyChequebook
(
ctx
context
.
Context
,
chequebook
common
.
Address
)
error
{
deployed
,
err
:=
c
.
verifyChequebookAgainstFactory
(
ctx
,
c
.
address
,
chequebook
)
if
err
!=
nil
{
return
err
}
if
deployed
{
return
nil
}
for
_
,
factoryAddress
:=
range
c
.
legacyAddresses
{
deployed
,
err
:=
c
.
verifyChequebookAgainstFactory
(
ctx
,
factoryAddress
,
chequebook
)
if
err
!=
nil
{
return
err
}
if
deployed
{
return
nil
}
}
return
ErrNotDeployedByFactory
}
}
// ERC20Address returns the token for which this factory deploys chequebooks.
// ERC20Address returns the token for which this factory deploys chequebooks.
...
@@ -178,10 +227,12 @@ func (c *factory) ERC20Address(ctx context.Context) (common.Address, error) {
...
@@ -178,10 +227,12 @@ func (c *factory) ERC20Address(ctx context.Context) (common.Address, error) {
}
}
// DiscoverFactoryAddress returns the canonical factory for this chainID
// DiscoverFactoryAddress returns the canonical factory for this chainID
func
DiscoverFactoryAddress
(
chainID
int64
)
(
c
ommon
.
Address
,
bool
)
{
func
DiscoverFactoryAddress
(
chainID
int64
)
(
c
urrentFactory
common
.
Address
,
legacyFactories
[]
common
.
Address
,
found
bool
)
{
if
chainID
==
5
{
if
chainID
==
5
{
// goerli
// goerli
return
common
.
HexToAddress
(
"0xf0277caffea72734853b834afc9892461ea18474"
),
true
return
common
.
HexToAddress
(
"0x73c412512E1cA0be3b89b77aB3466dA6A1B9d273"
),
[]
common
.
Address
{
common
.
HexToAddress
(
"0xf0277caffea72734853b834afc9892461ea18474"
),
},
true
}
}
return
common
.
Address
{},
false
return
common
.
Address
{},
nil
,
false
}
}
pkg/settlement/swap/chequebook/factory_test.go
View file @
5a012383
This diff is collapsed.
Click to expand it.
pkg/settlement/swap/chequebook/init.go
View file @
5a012383
...
@@ -6,6 +6,7 @@ package chequebook
...
@@ -6,6 +6,7 @@ package chequebook
import
(
import
(
"context"
"context"
"crypto/rand"
"fmt"
"fmt"
"math/big"
"math/big"
"time"
"time"
...
@@ -137,8 +138,14 @@ func Init(
...
@@ -137,8 +138,14 @@ func Init(
}
}
}
}
nonce
:=
make
([]
byte
,
32
)
_
,
err
=
rand
.
Read
(
nonce
)
if
err
!=
nil
{
return
nil
,
err
}
// if we don't yet have a chequebook, deploy a new one
// if we don't yet have a chequebook, deploy a new one
txHash
,
err
=
chequebookFactory
.
Deploy
(
ctx
,
overlayEthAddress
,
big
.
NewInt
(
0
))
txHash
,
err
=
chequebookFactory
.
Deploy
(
ctx
,
overlayEthAddress
,
big
.
NewInt
(
0
)
,
common
.
BytesToHash
(
nonce
)
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/settlement/swap/erc20/erc20_test.go
View file @
5a012383
...
@@ -31,6 +31,7 @@ func TestBalanceOf(t *testing.T) {
...
@@ -31,6 +31,7 @@ func TestBalanceOf(t *testing.T) {
transactionmock
.
New
(
transactionmock
.
New
(
transactionmock
.
WithABICall
(
transactionmock
.
WithABICall
(
&
erc20ABI
,
&
erc20ABI
,
erc20Address
,
expectedBalance
.
FillBytes
(
make
([]
byte
,
32
)),
expectedBalance
.
FillBytes
(
make
([]
byte
,
32
)),
"balanceOf"
,
"balanceOf"
,
account
,
account
,
...
...
pkg/settlement/swap/transaction/mock/transaction.go
View file @
5a012383
...
@@ -89,13 +89,15 @@ func New(opts ...Option) transaction.Service {
...
@@ -89,13 +89,15 @@ func New(opts ...Option) transaction.Service {
type
Call
struct
{
type
Call
struct
{
abi
*
abi
.
ABI
abi
*
abi
.
ABI
to
common
.
Address
result
[]
byte
result
[]
byte
method
string
method
string
params
[]
interface
{}
params
[]
interface
{}
}
}
func
ABICall
(
abi
*
abi
.
ABI
,
result
[]
byte
,
method
string
,
params
...
interface
{})
Call
{
func
ABICall
(
abi
*
abi
.
ABI
,
to
common
.
Address
,
result
[]
byte
,
method
string
,
params
...
interface
{})
Call
{
return
Call
{
return
Call
{
to
:
to
,
abi
:
abi
,
abi
:
abi
,
result
:
result
,
result
:
result
,
method
:
method
,
method
:
method
,
...
@@ -121,6 +123,13 @@ func WithABICallSequence(calls ...Call) Option {
...
@@ -121,6 +123,13 @@ func WithABICallSequence(calls ...Call) Option {
return
nil
,
fmt
.
Errorf
(
"wrong data. wanted %x, got %x"
,
data
,
request
.
Data
)
return
nil
,
fmt
.
Errorf
(
"wrong data. wanted %x, got %x"
,
data
,
request
.
Data
)
}
}
if
request
.
To
==
nil
{
return
nil
,
errors
.
New
(
"call with no recipient"
)
}
if
*
request
.
To
!=
call
.
to
{
return
nil
,
fmt
.
Errorf
(
"wrong recipient. wanted %x, got %x"
,
call
.
to
,
*
request
.
To
)
}
calls
=
calls
[
1
:
]
calls
=
calls
[
1
:
]
return
call
.
result
,
nil
return
call
.
result
,
nil
...
@@ -128,8 +137,8 @@ func WithABICallSequence(calls ...Call) Option {
...
@@ -128,8 +137,8 @@ func WithABICallSequence(calls ...Call) Option {
})
})
}
}
func
WithABICall
(
abi
*
abi
.
ABI
,
result
[]
byte
,
method
string
,
params
...
interface
{})
Option
{
func
WithABICall
(
abi
*
abi
.
ABI
,
to
common
.
Address
,
result
[]
byte
,
method
string
,
params
...
interface
{})
Option
{
return
WithABICallSequence
(
ABICall
(
abi
,
result
,
method
,
params
...
))
return
WithABICallSequence
(
ABICall
(
abi
,
to
,
result
,
method
,
params
...
))
}
}
func
WithABISend
(
abi
*
abi
.
ABI
,
txHash
common
.
Hash
,
expectedAddress
common
.
Address
,
expectedValue
*
big
.
Int
,
method
string
,
params
...
interface
{})
Option
{
func
WithABISend
(
abi
*
abi
.
ABI
,
txHash
common
.
Hash
,
expectedAddress
common
.
Address
,
expectedValue
*
big
.
Int
,
method
string
,
params
...
interface
{})
Option
{
...
...
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