stasatdaglabs 8a4ece1101
[NOD-1223] Reorganize project (#868)
* [NOD-1223] Move all network stuff into a new network package.

* [NOD-1223] Delete the unused package testutil.

* [NOD-1223] Move infrastructure stuff into a new instrastructure package.

* [NOD-1223] Move domain stuff into a new domain package.
2020-08-13 17:27:25 +03:00

46 lines
1.3 KiB
Go

package dbaccess
import (
"github.com/kaspanet/kaspad/infrastructure/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)
}