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
62f0c294
Commit
62f0c294
authored
Jun 25, 2021
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add persist config.
parent
3d9bcfd1
Pipeline
#447
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
node.go
pkg/node/node.go
+8
-0
persistconfig.go
pkg/node/persistconfig.go
+63
-0
No files found.
pkg/node/node.go
View file @
62f0c294
...
@@ -79,6 +79,7 @@ import (
...
@@ -79,6 +79,7 @@ import (
)
)
type
Bee
struct
{
type
Bee
struct
{
persistCfg
*
PersistConfig
p2pService
io
.
Closer
p2pService
io
.
Closer
p2pHalter
p2p
.
Halter
p2pHalter
p2p
.
Halter
p2pCancel
context
.
CancelFunc
p2pCancel
context
.
CancelFunc
...
@@ -188,6 +189,7 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
...
@@ -188,6 +189,7 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
errorLogWriter
:
logger
.
WriterLevel
(
logrus
.
ErrorLevel
),
errorLogWriter
:
logger
.
WriterLevel
(
logrus
.
ErrorLevel
),
tracerCloser
:
tracerCloser
,
tracerCloser
:
tracerCloser
,
}
}
b
.
initPersistConfig
(
o
.
DataDir
)
stateStore
,
err
:=
InitStateStore
(
logger
,
o
.
DataDir
)
stateStore
,
err
:=
InitStateStore
(
logger
,
o
.
DataDir
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -334,11 +336,17 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
...
@@ -334,11 +336,17 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
return
nil
,
fmt
.
Errorf
(
"invalid transaction hash: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid transaction hash: %w"
,
err
)
}
}
if
o
.
BlockHash
==
""
{
o
.
BlockHash
=
b
.
GetNextBlock
(
common
.
Bytes2Hex
(
txHash
))
}
blockHash
,
err
=
GetTxNextBlock
(
p2pCtx
,
logger
,
swapBackend
,
transactionMonitor
,
pollingInterval
,
txHash
,
o
.
BlockHash
)
blockHash
,
err
=
GetTxNextBlock
(
p2pCtx
,
logger
,
swapBackend
,
transactionMonitor
,
pollingInterval
,
txHash
,
o
.
BlockHash
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid block hash: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid block hash: %w"
,
err
)
}
}
b
.
UpdateTxNextBlock
(
common
.
Bytes2Hex
(
txHash
),
common
.
Bytes2Hex
(
blockHash
))
swarmAddress
,
err
:=
crypto
.
NewOverlayAddress
(
*
pubKey
,
networkID
,
blockHash
)
swarmAddress
,
err
:=
crypto
.
NewOverlayAddress
(
*
pubKey
,
networkID
,
blockHash
)
err
=
CheckOverlayWithStore
(
swarmAddress
,
stateStore
)
err
=
CheckOverlayWithStore
(
swarmAddress
,
stateStore
)
...
...
pkg/node/persistconfig.go
0 → 100644
View file @
62f0c294
package
node
import
(
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
const
(
persistFile
=
".persist.json"
)
type
PersistConfig
struct
{
ChequeBookTx
string
`json:"cheque_book_tx"`
TxNextBlockHash
string
`json:"tx_next_block_hash"`
Datadir
string
}
func
(
c
*
Bee
)
initPersistConfig
(
datadir
string
)
(
err
error
)
{
cfgfile
:=
filepath
.
Join
(
datadir
,
persistFile
)
var
cfg
PersistConfig
content
,
err
:=
ioutil
.
ReadFile
(
cfgfile
)
if
err
==
nil
{
json
.
Unmarshal
(
content
,
&
cfg
)
}
cfg
.
Datadir
=
datadir
c
.
persistCfg
=
&
cfg
return
nil
}
func
(
c
*
Bee
)
SavePersistConfig
()
(
err
error
)
{
basepath
:=
c
.
persistCfg
.
Datadir
cfgfile
:=
filepath
.
Join
(
basepath
,
persistFile
)
bytes
,
_
:=
json
.
Marshal
(
c
.
persistCfg
)
err
=
ioutil
.
WriteFile
(
cfgfile
+
".tmp"
,
bytes
,
0600
)
if
err
!=
nil
{
return
err
}
err
=
os
.
Rename
(
cfgfile
+
".tmp"
,
cfgfile
)
if
err
!=
nil
{
os
.
Remove
(
cfgfile
+
".tmp"
)
return
err
}
return
nil
}
func
(
c
*
Bee
)
GetNextBlock
(
txhash
string
)
string
{
if
c
.
persistCfg
.
TxNextBlockHash
!=
""
&&
strings
.
Compare
(
txhash
,
c
.
persistCfg
.
ChequeBookTx
)
==
0
{
return
c
.
persistCfg
.
TxNextBlockHash
}
return
""
}
func
(
c
*
Bee
)
UpdateTxNextBlock
(
txhash
string
,
nextBlock
string
)
{
c
.
persistCfg
.
ChequeBookTx
=
txhash
c
.
persistCfg
.
TxNextBlockHash
=
nextBlock
c
.
SavePersistConfig
()
}
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