Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 42f5960
Showing
7 changed files
with
1,215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 The Sia Foundation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# [![Sia Core](https://sia.tech/assets/banners/sia-banner-core.png)](http://sia.tech) | ||
|
||
[![GoDoc](https://godoc.org/go.sia.tech/coreutils?status.svg)](https://godoc.org/go.sia.tech/coreutils) | ||
|
||
This repo contains implementations of core Sia components, such as a P2P syncing/relay node, database-backed blockchain state manager, single-address wallet, and more. It is intended for use by Sia node implementations like `walletd`, `renterd`, and `hostd`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package coreutils | ||
|
||
import ( | ||
"go.etcd.io/bbolt" | ||
"go.sia.tech/core/chain" | ||
) | ||
|
||
// BoltChainDB implements chain.DB with a BoltDB database. | ||
type BoltChainDB struct { | ||
tx *bbolt.Tx | ||
db *bbolt.DB | ||
} | ||
|
||
func (db *BoltChainDB) newTx() (err error) { | ||
if db.tx == nil { | ||
db.tx, err = db.db.Begin(true) | ||
} | ||
return | ||
} | ||
|
||
// Bucket implements chain.DB. | ||
func (db *BoltChainDB) Bucket(name []byte) chain.DBBucket { | ||
if err := db.newTx(); err != nil { | ||
panic(err) | ||
} | ||
// NOTE: can't simply return db.tx.Bucket here, since it returns a concrete | ||
// type and we need a nil interface if the bucket does not exist | ||
b := db.tx.Bucket(name) | ||
if b == nil { | ||
return nil | ||
} | ||
return b | ||
} | ||
|
||
// CreateBucket implements chain.DB. | ||
func (db *BoltChainDB) CreateBucket(name []byte) (chain.DBBucket, error) { | ||
if err := db.newTx(); err != nil { | ||
return nil, err | ||
} | ||
// NOTE: unlike Bucket, ok to return directly here, because caller should | ||
// always check err first | ||
return db.tx.CreateBucket(name) | ||
} | ||
|
||
// Flush implements chain.DB. | ||
func (db *BoltChainDB) Flush() error { | ||
if db.tx == nil { | ||
return nil | ||
} | ||
err := db.tx.Commit() | ||
db.tx = nil | ||
return err | ||
} | ||
|
||
// Cancel implements chain.DB. | ||
func (db *BoltChainDB) Cancel() { | ||
if db.tx == nil { | ||
return | ||
} | ||
db.tx.Rollback() | ||
db.tx = nil | ||
} | ||
|
||
// Close closes the BoltDB database. | ||
func (db *BoltChainDB) Close() error { | ||
db.Flush() | ||
return db.db.Close() | ||
} | ||
|
||
// NewBoltChainDB creates a new BoltChainDB. | ||
func NewBoltChainDB(db *bbolt.DB) *BoltChainDB { | ||
return &BoltChainDB{db: db} | ||
} | ||
|
||
// OpenBoltChainDB opens a BoltDB database. | ||
func OpenBoltChainDB(path string) (*BoltChainDB, error) { | ||
db, err := bbolt.Open(path, 0600, nil) | ||
return NewBoltChainDB(db), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module go.sia.tech/coreutils | ||
|
||
go 1.21.5 | ||
|
||
require ( | ||
go.etcd.io/bbolt v1.3.8 | ||
go.sia.tech/core v0.1.12 | ||
) | ||
|
||
require ( | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect | ||
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
lukechampine.com/frand v1.4.2 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY= | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | ||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= | ||
go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= | ||
go.sia.tech/core v0.1.11 h1:fRI8Mp1G280pOy0WYXSu6nI5dDDGPjHX1fbDwpwZLvc= | ||
go.sia.tech/core v0.1.11/go.mod h1:D17UWSn99SEfQnEaR9G9n6Kz9+BwqMoUgZ6Cl424LsQ= | ||
go.sia.tech/core v0.1.12 h1:nrq/BvYbTGVLtZu0MHBTExUAP5nfNbcGhaJbuK839gc= | ||
go.sia.tech/core v0.1.12/go.mod h1:3EoY+rR78w1/uGoXXVqcYdwSjSJKuEMI5bL7WROA27Q= | ||
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8= | ||
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= | ||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= | ||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
lukechampine.com/frand v1.4.2 h1:RzFIpOvkMXuPMBb9maa4ND4wjBn71E1Jpf8BzJHMaVw= | ||
lukechampine.com/frand v1.4.2/go.mod h1:4S/TM2ZgrKejMcKMbeLjISpJMO+/eZ1zu3vYX9dtj3s= |
Oops, something went wrong.