This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
26 changed files
with
1,300 additions
and
77 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
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,27 @@ | ||
package clientdb | ||
|
||
import ( | ||
"github.com/c3systems/go-substrate/common/db" | ||
) | ||
|
||
func createU8a(dbs *db.BaseDB, fn func()) StorageMethodU8a { | ||
// TODO | ||
return StorageMethodU8a{} | ||
} | ||
|
||
func createBn(dbs *db.BaseDB, fn func(), n int) StorageMethodBn { | ||
// TODO | ||
return StorageMethodBn{} | ||
} | ||
|
||
// NewBlockDB ... | ||
func NewBlockDB(dbs *db.BaseDB) *BlockDB { | ||
return &BlockDB{ | ||
DB: *dbs, | ||
BestHash: createU8a(dbs, KeyBestHash()), | ||
BestNumber: createBn(dbs, KeyBestNumber(), 64), | ||
BlockData: createU8a(dbs, KeyBlockByHash()), | ||
Header: createU8a(dbs, KeyHeaderByHash()), | ||
Hash: createU8a(dbs, KeyHashByNumber()), | ||
} | ||
} |
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,4 @@ | ||
package clientdb | ||
|
||
// https://github.com/polkadot-js/client/tree/master/packages/client-db/src | ||
// TODO |
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,6 @@ | ||
package clientdb | ||
|
||
import "testing" | ||
|
||
func TestClientDB(t *testing.T) { | ||
} |
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,121 @@ | ||
package clientdb | ||
|
||
// StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType from @polkadot/types/Metadata/Modules | ||
// createFunction from @polkadot/storage/utils/createFunction | ||
|
||
// MetadataType ... | ||
type MetadataType struct { | ||
Key string | ||
Value string | ||
} | ||
|
||
// SubstrateMetadata ... | ||
type SubstrateMetadata struct { | ||
Documentation []string | ||
Type MetadataType | ||
} | ||
|
||
// CreateItemOptions ... | ||
type CreateItemOptions struct { | ||
IsUnhashed bool | ||
Key string | ||
} | ||
|
||
// StorageFunctionMetadata ... | ||
type StorageFunctionMetadata struct { | ||
//Documention *Vector | ||
//Modifier *Modifier | ||
//Type *StorageFunction | ||
//ToJSON * | ||
} | ||
|
||
// CreateFunc ... | ||
func CreateFunc(StorageFunctionMetadata, CreateItemOptions) func() { | ||
// TODO | ||
return func() { | ||
// TODO | ||
|
||
} | ||
} | ||
|
||
// CreateMethod is small helper function to factorize code on this page | ||
func CreateMethod(method string, key string, meta SubstrateMetadata) func() { | ||
b := 1 | ||
if meta.Type.Value == "" { | ||
b = 0 | ||
} | ||
_ = b | ||
|
||
// TODO | ||
return CreateFunc( | ||
//NewText("Block"), // @polkadot/types/Text | ||
//NewText(method), | ||
StorageFunctionMetadata{ | ||
/* | ||
Documentation: NewVector(Text, meta.Documention), // @polkadot/types/codec/Vector | ||
Modifier: NewStorageFunctionModifier(0), | ||
Type: NewStorageFunction(meta.Type, b), | ||
*/ | ||
//ToJSON: func() interface{} { | ||
// return key | ||
//}, | ||
}, | ||
CreateItemOptions{ | ||
IsUnhashed: false, | ||
Key: key, | ||
}, | ||
) | ||
} | ||
|
||
// KeyBestHash ... | ||
func KeyBestHash() func() { | ||
return CreateMethod("bestHash", "bst:hsh", SubstrateMetadata{ | ||
Documentation: []string{"Best hash"}, | ||
Type: MetadataType{ | ||
Key: "Hash", | ||
}, | ||
}) | ||
} | ||
|
||
// KeyBestNumber ... | ||
func KeyBestNumber() func() { | ||
return CreateMethod("bestNumber", "bst:num", SubstrateMetadata{ | ||
Documentation: []string{"Best block"}, | ||
Type: MetadataType{ | ||
Key: "BlockNumber", | ||
}, | ||
}) | ||
} | ||
|
||
// KeyBlockByHash ... | ||
func KeyBlockByHash() func() { | ||
return CreateMethod("blockByHash", "blk:hsh", SubstrateMetadata{ | ||
Documentation: []string{"Retrieve block by hash"}, | ||
Type: MetadataType{ | ||
Key: "Hash", | ||
Value: "Bytes", | ||
}, | ||
}) | ||
} | ||
|
||
// KeyHashByNumber ... | ||
func KeyHashByNumber() func() { | ||
return CreateMethod("hashByNumber", "hsh:num", SubstrateMetadata{ | ||
Documentation: []string{"Retrieve hash by number"}, | ||
Type: MetadataType{ | ||
Key: "u256", | ||
Value: "Hash", | ||
}, | ||
}) | ||
} | ||
|
||
// KeyHeaderByHash ... | ||
func KeyHeaderByHash() func() { | ||
return CreateMethod("headerByHash", "hdr:hsh", SubstrateMetadata{ | ||
Documentation: []string{"Retrieve header by hash"}, | ||
Type: MetadataType{ | ||
Key: "Hash", | ||
Value: "Bytes", | ||
}, | ||
}) | ||
} |
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 @@ | ||
package clientdb |
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,66 @@ | ||
package clientdb | ||
|
||
import ( | ||
"github.com/c3systems/go-substrate/common/db" | ||
"github.com/c3systems/go-substrate/common/triedb" | ||
) | ||
|
||
// DefaultPath ... | ||
var DefaultPath = "~/.go-substrate" | ||
|
||
// DefaultType ... | ||
var DefaultType = "disk" | ||
|
||
// DBPathPrefix ... | ||
var DBPathPrefix = "database" | ||
|
||
// DBConfigType ... | ||
var DBConfigType = "disk" // other option is "memory" | ||
|
||
// DBConfig ... | ||
type DBConfig struct { | ||
Compact bool | ||
IsTrieDb bool | ||
Path string | ||
Snapshot bool | ||
Type string // DBConfigType | ||
} | ||
|
||
// BlockDB ... | ||
type BlockDB struct { | ||
DB db.BaseDB | ||
BestHash StorageMethodU8a | ||
BestNumber StorageMethodBn | ||
BlockData StorageMethodU8a | ||
Hash StorageMethodU8a | ||
Header StorageMethodU8a | ||
} | ||
|
||
// StateDB ... | ||
type StateDB struct { | ||
db *triedb.TrieDB | ||
code StorageMethodU8a | ||
} | ||
|
||
// ChainDbs ... | ||
type ChainDbs interface { | ||
Snapshot() | ||
} | ||
|
||
// StorageMethodU8a ... | ||
// TODO | ||
type StorageMethodU8a struct { | ||
//Del(params ...interface{}) | ||
//Get(params ...interface{}) []uint8 | ||
//Set(value []uint8, params ...interface{}) | ||
//OnUpdate(callback func(value []uint8)) | ||
} | ||
|
||
// StorageMethodBn ... | ||
// TODO | ||
type StorageMethodBn struct { | ||
//Del(params ...interface{}) | ||
//Get(params ...interface{}) *big.Int | ||
//Set(value *big.Int, params ...interface{}) | ||
//OnUpdate(callback func(value *big.Int)) | ||
} |
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
Oops, something went wrong.