mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-22 14:02:32 +00:00

* [NOD-1223] Delete unused files/packages. * [NOD-1223] Move signal and limits to the os package. * [NOD-1223] Put database and dbaccess into the db package. * [NOD-1223] Fold the logs package into the logger package. * [NOD-1223] Rename domainmessage to appmessage. * [NOD-1223] Rename to/from DomainMessage to AppMessage. * [NOD-1223] Move appmessage to the app packge. * [NOD-1223] Move protocol to the app packge. * [NOD-1223] Move the network package to the infrastructure packge. * [NOD-1223] Rename cmd to executables. * [NOD-1223] Fix go.doc in the logger package.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package dbaccess
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/infrastructure/db/database"
|
|
"github.com/kaspanet/kaspad/util/subnetworkid"
|
|
)
|
|
|
|
var subnetworkBucket = database.MakeBucket([]byte("subnetworks"))
|
|
|
|
func subnetworkKey(subnetworkID *subnetworkid.SubnetworkID) *database.Key {
|
|
return subnetworkBucket.Key(subnetworkID[:])
|
|
}
|
|
|
|
// FetchSubnetworkData returns the subnetwork data by its ID.
|
|
func FetchSubnetworkData(context Context, subnetworkID *subnetworkid.SubnetworkID) ([]byte, error) {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
key := subnetworkKey(subnetworkID)
|
|
return accessor.Get(key)
|
|
}
|
|
|
|
// StoreSubnetwork stores mappings from ID of the subnetwork to the subnetwork data.
|
|
func StoreSubnetwork(context Context, subnetworkID *subnetworkid.SubnetworkID, subnetworkData []byte) error {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
key := subnetworkKey(subnetworkID)
|
|
return accessor.Put(key, subnetworkData)
|
|
}
|
|
|
|
// HasSubnetwork returns whether the subnetwork exists in the database.
|
|
func HasSubnetwork(context Context, subnetworkID *subnetworkid.SubnetworkID) (bool, error) {
|
|
accessor, err := context.accessor()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
key := subnetworkKey(subnetworkID)
|
|
return accessor.Has(key)
|
|
}
|