From d7f454fe4c09e140ed1fe8202478f1525cf9a7ee Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Wed, 4 Sep 2019 08:25:33 +0200 Subject: [PATCH] Add mailservers service (#1595) --- api/backend.go | 8 + appdatabase/migrations/bindata.go | 272 ++++++++++++++++--- appdatabase/migrations/sql/0001_app.down.sql | 1 + appdatabase/migrations/sql/0001_app.up.sql | 8 + mailserver/migrations/bindata.go | 110 +++++--- params/config.go | 9 + services/mailservers/README.md | 45 +++ services/mailservers/api.go | 24 ++ services/mailservers/api_test.go | 56 ++++ services/mailservers/database.go | 82 ++++++ services/mailservers/service.go | 37 +++ static/bindata.go | 199 +++++++++----- t/bindata.go | 108 +++++--- 13 files changed, 773 insertions(+), 186 deletions(-) create mode 100644 services/mailservers/README.md create mode 100644 services/mailservers/api.go create mode 100644 services/mailservers/api_test.go create mode 100644 services/mailservers/database.go create mode 100644 services/mailservers/service.go diff --git a/api/backend.go b/api/backend.go index c743527ec..701a28d40 100644 --- a/api/backend.go +++ b/api/backend.go @@ -32,6 +32,7 @@ import ( "github.com/status-im/status-go/rpc" accountssvc "github.com/status-im/status-go/services/accounts" "github.com/status-im/status-go/services/browsers" + "github.com/status-im/status-go/services/mailservers" "github.com/status-im/status-go/services/permissions" "github.com/status-im/status-go/services/personal" "github.com/status-im/status-go/services/rpcfilters" @@ -363,6 +364,12 @@ func (b *StatusBackend) permissionsService() gethnode.ServiceConstructor { } } +func (b *StatusBackend) mailserversService() gethnode.ServiceConstructor { + return func(*gethnode.ServiceContext) (gethnode.Service, error) { + return mailservers.NewService(mailservers.NewDB(b.appDB)), nil + } +} + func (b *StatusBackend) walletService(network uint64, accountsFeed *event.Feed) gethnode.ServiceConstructor { return func(*gethnode.ServiceContext) (gethnode.Service, error) { return wallet.NewService(wallet.NewDB(b.appDB, network), accountsFeed), nil @@ -387,6 +394,7 @@ func (b *StatusBackend) startNode(config *params.NodeConfig) (err error) { services = appendIf(b.appDB != nil && b.multiaccountsDB != nil, services, b.accountsService(accountsFeed)) services = appendIf(config.BrowsersConfig.Enabled, services, b.browsersService()) services = appendIf(config.PermissionsConfig.Enabled, services, b.permissionsService()) + services = appendIf(config.MailserversConfig.Enabled, services, b.mailserversService()) services = appendIf(config.WalletConfig.Enabled, services, b.walletService(config.NetworkID, accountsFeed)) manager := b.accountManager.GetManager() diff --git a/appdatabase/migrations/bindata.go b/appdatabase/migrations/bindata.go index 462005160..8db8dcf8d 100644 --- a/appdatabase/migrations/bindata.go +++ b/appdatabase/migrations/bindata.go @@ -1,68 +1,216 @@ +// Code generated by go-bindata. DO NOT EDIT. +// sources: +// 0001_app.down.sql (230B) +// 0001_app.up.sql (2.246kB) +// doc.go (74B) + package migrations import ( "bytes" "compress/gzip" + "crypto/sha256" "fmt" "io" + "io/ioutil" + "os" + "path/filepath" "strings" + "time" ) -func bindata_read(data []byte, name string) ([]byte, error) { +func bindataRead(data []byte, name string) ([]byte, error) { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } var buf bytes.Buffer _, err = io.Copy(&buf, gz) - gz.Close() + clErr := gz.Close() if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) + } + if clErr != nil { + return nil, err } return buf.Bytes(), nil } -var __0001_app_down_sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\xb6\xe6\x42\x12\x4c\x4c\x4e\xce\x2f\xcd\x2b\x41\x15\x4c\x2a\xca\x2f\x2f\x4e\x2d\xc2\x2e\x18\x9f\x91\x59\x5c\x92\x5f\x54\x89\x22\x99\x92\x58\x50\x80\xaa\xbc\x20\xb5\x28\x37\xb3\xb8\x38\x33\x3f\x0f\x55\xbc\xa4\x28\x31\xaf\x38\x0d\xc3\xf0\x9c\xfc\xe4\x6c\xec\x2e\x8b\x2f\xc9\x8f\x87\x49\x03\x02\x00\x00\xff\xff\xe3\xa7\x2d\xc9\xce\x00\x00\x00") +type asset struct { + bytes []byte + info os.FileInfo + digest [sha256.Size]byte +} -func _0001_app_down_sql() ([]byte, error) { - return bindata_read( - __0001_app_down_sql, +type bindataFileInfo struct { + name string + size int64 + mode os.FileMode + modTime time.Time +} + +func (fi bindataFileInfo) Name() string { + return fi.name +} +func (fi bindataFileInfo) Size() int64 { + return fi.size +} +func (fi bindataFileInfo) Mode() os.FileMode { + return fi.mode +} +func (fi bindataFileInfo) ModTime() time.Time { + return fi.modTime +} +func (fi bindataFileInfo) IsDir() bool { + return false +} +func (fi bindataFileInfo) Sys() interface{} { + return nil +} + +var __0001_appDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\xb6\xe6\x42\x12\x4c\x4c\x4e\xce\x2f\xcd\x2b\x41\x15\x4c\x2a\xca\x2f\x2f\x4e\x2d\xc2\x2e\x18\x9f\x91\x59\x5c\x92\x5f\x54\x89\x22\x99\x92\x58\x50\x80\xaa\xbc\x20\xb5\x28\x37\xb3\xb8\x38\x33\x3f\x0f\x55\xbc\xa4\x28\x31\xaf\x38\x0d\xc3\xf0\x9c\xfc\xe4\x6c\xec\x2e\x8b\x2f\xc9\x8f\xc7\x22\x9d\x9b\x98\x99\x53\x9c\x5a\x54\x06\x36\x09\x10\x00\x00\xff\xff\xd2\xa8\x66\x23\xe6\x00\x00\x00") + +func _0001_appDownSqlBytes() ([]byte, error) { + return bindataRead( + __0001_appDownSql, "0001_app.down.sql", ) } -var __0001_app_up_sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x54\x5d\x93\x9a\x30\x14\x7d\xcf\xaf\xb8\x8f\x3a\xc3\x3f\xd8\x27\xd4\xe8\x66\x4a\x43\xcb\x47\x77\xf7\x89\x89\x90\x55\x46\x0c\x34\x89\x75\xfd\xf7\x9d\x00\x01\x74\x11\xbb\xd3\x37\x92\x9c\x1c\xce\x39\xf7\xde\x2c\x03\xec\x46\x18\x22\x77\xe1\x61\x20\x6b\xa0\x7e\x04\xf8\x95\x84\x51\x08\x8a\x6b\x9d\x8b\x9d\x82\x19\xd2\x97\x8a\xc3\x2f\x37\x58\x3e\xbb\x01\xfc\x08\xc8\x77\x37\x78\x83\x6f\xf8\xcd\x41\x7f\x58\x71\xe2\xb0\xf0\xfc\x05\x9a\xc3\x0b\x89\x9e\xfd\x38\x82\xc0\x7f\x21\xab\x27\x84\x26\xc8\x59\x9a\x96\x27\xa1\x0d\x39\xcb\x32\xc9\x95\x1a\xe7\x3f\xb3\xa2\xe0\x1a\x16\xbe\xef\x61\x97\x3a\x28\xdd\xb3\xc1\xaa\xd6\x15\xe1\xd7\xc8\x41\x4a\x97\x92\xed\xec\xaa\x3a\x6d\x0f\xfc\x52\xeb\x72\x50\xc5\xf4\xbe\xdd\x17\xec\x68\x21\x69\x59\x94\xb2\xfe\xbe\xaf\x3c\xa6\xe4\x67\x8c\x81\xd0\x15\x7e\x85\x93\xc8\x7f\x9f\x78\xd2\x28\x4a\xac\x6a\x9f\x0e\xbc\x34\x67\x73\x78\x79\xc6\x01\xee\x96\x4f\x53\x74\xc6\xd0\x38\x99\x39\xe9\xa8\xea\xc5\x74\xa4\x5b\x59\x9e\x15\x97\x26\xd2\x3c\xab\x8d\x5d\x47\xd9\x79\xaf\x2f\xd1\xd8\xf3\x1c\xa4\xf3\x23\x57\x9a\x1d\x2b\x88\xc3\x0d\xd9\x50\xbc\x82\x05\xd9\x10\x1a\x39\x28\x63\x55\x65\x93\x86\x15\x5e\xbb\xb1\x17\xc1\x3b\x2b\x14\x77\xd0\x3e\x37\x71\x5f\x88\xc8\xf8\x07\xc4\x34\x6c\x6e\x12\x3a\x11\xe5\x94\xe2\xa4\xe5\x83\x19\x6a\xb7\x12\xeb\xa0\x97\x6a\x31\x4d\xf5\xd6\x7e\x80\xc9\x86\x1a\x67\xb3\xfe\xce\x1c\x02\xbc\xc6\x01\xa6\x4b\xdc\xb3\xcf\xcc\xbe\x6f\x3c\x78\x38\xc2\xb0\x74\xc3\xa5\xbb\xc2\xe8\x41\x9a\xc6\xbe\x89\xb2\x4f\x6d\x10\xe6\xd7\x6c\x56\x5c\x1e\x73\xa5\xf2\x52\x18\x42\x43\x9c\x8c\xd5\xa2\x87\xdd\x9e\x0c\xcd\x76\xd7\xaf\xbc\xd6\x6a\x67\xcd\xf6\xb8\xd5\x29\x81\x5a\x32\xa1\xde\x9b\xd6\x11\x5c\x9f\x4b\x79\x30\x05\xe8\x0a\xdb\xb4\xc4\xb0\x16\x4c\xed\xbb\x79\xed\xb7\x6f\x27\xb9\x3f\xd9\x16\x87\xe4\xce\x25\xfd\xd1\x8e\xa9\xe2\x22\xe3\x72\x04\x21\x79\xca\xf3\x4a\xb7\xb0\xa2\xdc\xb5\x5f\x57\xaf\xd2\x78\x5a\xbd\x1b\xc7\x4a\xb8\xee\x91\xa2\x4c\x0f\x6a\x08\x6b\x20\x9f\x32\x74\xd0\xd2\xa7\x61\x14\xb8\x26\x88\x76\x74\x6d\x6c\x49\xc5\xa5\x1d\xe1\xfa\xbb\xa5\xb3\xf3\x3e\x33\x9c\x4e\x0b\x70\xfa\x7f\xcd\x1f\xf5\x60\xa3\xee\x3f\x8b\x22\x4e\xc7\x2d\x97\x9f\xe1\x83\xd1\xbf\x4f\xc9\x59\x56\xbf\x01\xdd\x03\xb0\x76\xbd\x70\x34\x8c\x5a\xeb\xa8\xfb\xdb\x70\xef\x5e\x6e\x94\x3e\xe2\x68\x50\x0f\xb3\xb3\xef\x68\xa2\xcb\xe4\x6b\x39\x4e\x77\xf1\xbd\x38\xd5\x45\xa4\x50\x3f\x9c\x13\xfd\xd7\x6a\x9f\xee\x40\x0b\xfa\xa7\x1e\x3c\xb2\xaa\xca\xc5\x2e\x79\x2f\x65\xd2\x5a\xee\x1c\x8f\x26\x69\xdb\xb0\x97\x73\xdb\x91\x7f\x03\x00\x00\xff\xff\xd0\x65\x6e\xd9\x13\x08\x00\x00") +func _0001_appDownSql() (*asset, error) { + bytes, err := _0001_appDownSqlBytes() + if err != nil { + return nil, err + } -func _0001_app_up_sql() ([]byte, error) { - return bindata_read( - __0001_app_up_sql, + info := bindataFileInfo{name: "0001_app.down.sql", size: 230, mode: os.FileMode(0644), modTime: time.Unix(1567452784, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc6, 0x64, 0x5c, 0xd5, 0x35, 0x13, 0xe3, 0x6e, 0x9c, 0x61, 0x16, 0x4, 0x5d, 0x61, 0x79, 0xb2, 0xfd, 0x44, 0xa3, 0x6a, 0x1d, 0x8e, 0xd9, 0x50, 0x92, 0x2e, 0x34, 0xb2, 0x6, 0x3, 0xb7, 0xf1}} + return a, nil +} + +var __0001_appUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x55\xdd\x92\xa2\x3c\x10\xbd\xcf\x53\xf4\xa5\x56\xf1\x06\x73\x85\x1a\x1d\xea\xe3\x0b\xbb\xfc\xec\xcc\x5c\x51\x11\xa2\x52\xf2\xb7\x49\x1c\xc7\xb7\xdf\x0a\x21\x80\x23\xe2\x5a\x7b\x47\xd2\xdd\xc7\x73\x4e\xba\xdb\xa5\x8f\xed\x10\x43\x68\x2f\x5c\x0c\xce\x1a\x88\x17\x02\x7e\x77\x82\x30\x00\xc1\xa4\xcc\xca\xbd\x80\x19\x92\x97\x9a\xc1\x2f\xdb\x5f\xbe\xda\x3e\xfc\xf0\x9d\xff\x6d\xff\x03\xfe\xc3\x1f\x16\xfa\xa4\xf9\x89\xc1\xc2\xf5\x16\x68\x0e\x6f\x4e\xf8\xea\x45\x21\xf8\xde\x9b\xb3\x7a\x41\x68\x02\x9c\x26\x49\x75\x2a\xa5\x02\xa7\x69\xca\x99\x10\xe3\xf8\x67\x9a\xe7\x4c\xc2\xc2\xf3\x5c\x6c\x13\x0b\x25\x07\x3a\x38\x35\xbc\x42\xfc\x1e\x5a\x48\xc8\x8a\xd3\xbd\x39\xd5\xa7\xed\x91\x5d\x1a\x5e\x16\xaa\xa9\x3c\xb4\xf7\x25\x2d\x4c\x4a\x52\xe5\x15\x6f\xbe\xef\x33\x8f\x88\xf3\x33\xc2\xe0\x90\x15\x7e\x87\x53\x99\xfd\x3e\xb1\x58\x33\x8a\x0d\x6b\x8f\x0c\xb4\xe8\xd8\x1c\xde\x5e\xb1\x8f\xbb\xe3\xcb\x14\x9c\x12\x34\x0e\xa6\x22\x1d\x54\x73\x98\xb6\x74\xcb\xab\xb3\x60\x5c\x59\x9a\xa5\x8d\xb0\x6b\x2b\x3b\xed\x4d\x11\x89\x5c\xd7\x42\x32\x2b\x98\x90\xb4\xa8\x21\x0a\x36\xce\x86\xe0\x15\x2c\x9c\x8d\x43\x42\x0b\xa5\xb4\xae\x8d\xd3\xb0\xc2\x6b\x3b\x72\x43\xd8\xd1\x5c\x30\x0b\x1d\x32\x65\xf7\xc5\x29\x53\xf6\x05\x11\x09\x74\xa5\x43\x26\xac\x9c\x62\x1c\xb7\x78\x30\x43\xed\x55\x6c\x14\xf4\x54\x4d\x8e\x7e\xbd\xb5\xe7\x63\x67\x43\x94\xb2\x59\x5f\x33\x07\x1f\xaf\xb1\x8f\xc9\x12\xf7\xe8\x33\x75\xef\x29\x0d\x2e\x0e\x31\x2c\xed\x60\x69\xaf\x30\x7a\xe0\xa6\x92\xaf\xac\xec\x5d\x1b\x98\xf9\x9c\xcc\x9a\xf1\x22\x13\x22\xab\x4a\x05\xa8\x80\xe3\xb1\xb7\xe8\xd3\xbe\x47\x86\x62\xbb\xf2\x2b\xad\x0d\xdb\x99\xbe\x1e\x97\x3a\x45\x50\x72\x5a\x8a\x9d\x6e\x9d\x92\xc9\x73\xc5\x8f\xea\x01\xba\x87\xd5\x2d\x31\x7c\x0b\x2a\x0e\xdd\xbc\xf6\xd7\xdf\x27\xb9\x8f\x6c\xf3\x63\x7c\xa7\x48\x7e\xb5\x63\x2a\x58\x99\x32\x3e\x92\xc1\x59\xc2\xb2\x5a\xb6\x69\x79\xb5\x6f\xbf\xae\xb6\xd2\xb8\x5b\xbd\x1a\xcb\x50\xb8\xee\x91\xbc\x4a\x8e\x62\x98\xa6\x53\x6e\x3c\xb4\xd0\xd2\x23\x41\xe8\xdb\xca\x88\x76\x74\x8d\x6d\x71\xcd\xb8\x19\xe1\xe6\xbb\x85\x33\xf3\x3e\x53\x98\x56\x9b\x60\xf5\xbf\x35\x7f\xd4\x83\x9a\xdd\x3f\x3e\x4a\x79\x2a\xb6\x8c\xdf\xa6\x0f\x46\xff\x3e\x24\xa3\x69\xb3\x03\xba\x05\xb0\xb6\xdd\x60\xd4\x8c\x86\xeb\xa8\xfa\xef\xe6\xde\x2d\xd6\x4c\x1f\x61\xe8\xac\x87\xde\x99\x3d\x1a\xcb\x2a\x7e\xce\xc7\xe9\x2e\xbe\x67\xa7\xb8\x94\x09\x34\x8b\x73\xa2\xff\x5a\xee\xd3\x1d\x68\x92\xfe\xaa\x07\x0b\x5a\xd7\x59\xb9\x8f\x77\x15\x8f\x5b\xc9\x9d\xe2\x51\x27\x4d\x1b\xf6\x74\x9e\xe9\xc8\x82\x66\xb9\x60\xfc\x53\xef\x0a\x00\x80\x2c\x1d\xff\xe3\x56\xb1\x66\xcb\xdd\xda\xa8\x42\xf7\x4d\x56\xd1\x9a\x0a\x71\xae\x78\x07\xad\x6f\x77\x39\x63\xf2\xa6\x42\x51\xfe\x13\x00\x00\xff\xff\xe9\x5c\xa2\xa8\xc6\x08\x00\x00") + +func _0001_appUpSqlBytes() ([]byte, error) { + return bindataRead( + __0001_appUpSql, "0001_app.up.sql", ) } -var _doc_go = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00") +func _0001_appUpSql() (*asset, error) { + bytes, err := _0001_appUpSqlBytes() + if err != nil { + return nil, err + } -func doc_go() ([]byte, error) { - return bindata_read( - _doc_go, + info := bindataFileInfo{name: "0001_app.up.sql", size: 2246, mode: os.FileMode(0644), modTime: time.Unix(1567452763, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6e, 0xc4, 0x4d, 0x62, 0x9b, 0x4, 0x4e, 0xb1, 0x57, 0x51, 0x5c, 0xf7, 0x9, 0x9, 0x30, 0x38, 0x10, 0x1f, 0xc1, 0xcc, 0xe4, 0x56, 0x67, 0xa, 0x17, 0x3b, 0x51, 0x1f, 0x84, 0x12, 0xf4, 0x15}} + return a, nil +} + +var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00") + +func docGoBytes() ([]byte, error) { + return bindataRead( + _docGo, "doc.go", ) } +func docGo() (*asset, error) { + bytes, err := docGoBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "doc.go", size: 74, mode: os.FileMode(0644), modTime: time.Unix(1566753968, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x7c, 0x28, 0xcd, 0x47, 0xf2, 0xfa, 0x7c, 0x51, 0x2d, 0xd8, 0x38, 0xb, 0xb0, 0x34, 0x9d, 0x4c, 0x62, 0xa, 0x9e, 0x28, 0xc3, 0x31, 0x23, 0xd9, 0xbb, 0x89, 0x9f, 0xa0, 0x89, 0x1f, 0xe8}} + return a, nil +} + // Asset loads and returns the asset for the given name. // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { - return f() + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) + } + return a.bytes, nil } return nil, fmt.Errorf("Asset %s not found", name) } +// AssetString returns the asset contents as a string (instead of a []byte). +func AssetString(name string) (string, error) { + data, err := Asset(name) + return string(data), err +} + +// MustAsset is like Asset but panics when Asset would return an error. +// It simplifies safe initialization of global variables. +func MustAsset(name string) []byte { + a, err := Asset(name) + if err != nil { + panic("asset: Asset(" + name + "): " + err.Error()) + } + + return a +} + +// MustAssetString is like AssetString but panics when Asset would return an +// error. It simplifies safe initialization of global variables. +func MustAssetString(name string) string { + return string(MustAsset(name)) +} + +// AssetInfo loads and returns the asset info for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func AssetInfo(name string) (os.FileInfo, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) + } + return a.info, nil + } + return nil, fmt.Errorf("AssetInfo %s not found", name) +} + +// AssetDigest returns the digest of the file with the given name. It returns an +// error if the asset could not be found or the digest could not be loaded. +func AssetDigest(name string) ([sha256.Size]byte, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err) + } + return a.digest, nil + } + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name) +} + +// Digests returns a map of all known files and their checksums. +func Digests() (map[string][sha256.Size]byte, error) { + mp := make(map[string][sha256.Size]byte, len(_bindata)) + for name := range _bindata { + a, err := _bindata[name]() + if err != nil { + return nil, err + } + mp[name] = a.digest + } + return mp, nil +} + // AssetNames returns the names of the assets. func AssetNames() []string { names := make([]string, 0, len(_bindata)) @@ -73,11 +221,14 @@ func AssetNames() []string { } // _bindata is a table, holding each asset generator, mapped to its name. -var _bindata = map[string]func() ([]byte, error){ - "0001_app.down.sql": _0001_app_down_sql, - "0001_app.up.sql": _0001_app_up_sql, - "doc.go": doc_go, +var _bindata = map[string]func() (*asset, error){ + "0001_app.down.sql": _0001_appDownSql, + + "0001_app.up.sql": _0001_appUpSql, + + "doc.go": docGo, } + // AssetDir returns the file names below a certain // directory embedded in the file by go-bindata. // For example if you run go-bindata on data/... and data contains the @@ -87,15 +238,15 @@ var _bindata = map[string]func() ([]byte, error){ // img/ // a.png // b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// then AssetDir("data") would return []string{"foo.txt", "img"}, +// AssetDir("data/img") would return []string{"a.png", "b.png"}, +// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") + canonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(canonicalName, "/") for _, p := range pathList { node = node.Children[p] if node == nil { @@ -107,21 +258,62 @@ func AssetDir(name string) ([]string, error) { return nil, fmt.Errorf("Asset %s not found", name) } rv := make([]string, 0, len(node.Children)) - for name := range node.Children { - rv = append(rv, name) + for childName := range node.Children { + rv = append(rv, childName) } return rv, nil } -type _bintree_t struct { - Func func() ([]byte, error) - Children map[string]*_bintree_t +type bintree struct { + Func func() (*asset, error) + Children map[string]*bintree } -var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ - "0001_app.down.sql": &_bintree_t{_0001_app_down_sql, map[string]*_bintree_t{ - }}, - "0001_app.up.sql": &_bintree_t{_0001_app_up_sql, map[string]*_bintree_t{ - }}, - "doc.go": &_bintree_t{doc_go, map[string]*_bintree_t{ - }}, + +var _bintree = &bintree{nil, map[string]*bintree{ + "0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}}, + "0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}}, + "doc.go": &bintree{docGo, map[string]*bintree{}}, }} + +// RestoreAsset restores an asset under the given directory. +func RestoreAsset(dir, name string) error { + data, err := Asset(name) + if err != nil { + return err + } + info, err := AssetInfo(name) + if err != nil { + return err + } + err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) + if err != nil { + return err + } + err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) + if err != nil { + return err + } + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) +} + +// RestoreAssets restores an asset under the given directory recursively. +func RestoreAssets(dir, name string) error { + children, err := AssetDir(name) + // File + if err != nil { + return RestoreAsset(dir, name) + } + // Dir + for _, child := range children { + err = RestoreAssets(dir, filepath.Join(name, child)) + if err != nil { + return err + } + } + return nil +} + +func _filePath(dir, name string) string { + canonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) +} diff --git a/appdatabase/migrations/sql/0001_app.down.sql b/appdatabase/migrations/sql/0001_app.down.sql index ba7184d66..49d540130 100644 --- a/appdatabase/migrations/sql/0001_app.down.sql +++ b/appdatabase/migrations/sql/0001_app.down.sql @@ -7,3 +7,4 @@ DROP TABLE permissions; DROP TABLE transfers; DROP TABLE blocks; DROP TABLE accounts_to_blocks; +DROP TABLE mailservers; diff --git a/appdatabase/migrations/sql/0001_app.up.sql b/appdatabase/migrations/sql/0001_app.up.sql index 7c5c717de..f06d11a41 100644 --- a/appdatabase/migrations/sql/0001_app.up.sql +++ b/appdatabase/migrations/sql/0001_app.up.sql @@ -75,3 +75,11 @@ sync INT, FOREIGN KEY(network_id,blk_number) REFERENCES blocks(network_id,number) ON DELETE CASCADE, CONSTRAINT unique_mapping_for_account_to_block_per_network UNIQUE (address,blk_number,network_id) ); + +CREATE TABLE IF NOT EXISTS mailservers ( + id VARCHAR PRIMARY KEY, + name VARCHAR NOT NULL, + address VARCHAR NOT NULL, + password VARCHAR, + fleet VARCHAR NOT NULL +); diff --git a/mailserver/migrations/bindata.go b/mailserver/migrations/bindata.go index 042ba8619..aea505e16 100644 --- a/mailserver/migrations/bindata.go +++ b/mailserver/migrations/bindata.go @@ -1,15 +1,15 @@ -// Code generated by go-bindata. +// Code generated by go-bindata. DO NOT EDIT. // sources: -// 1557732988_initialize_db.down.sql -// 1557732988_initialize_db.up.sql -// static.go -// DO NOT EDIT! +// 1557732988_initialize_db.down.sql (72B) +// 1557732988_initialize_db.up.sql (234B) +// static.go (178B) package migrations import ( "bytes" "compress/gzip" + "crypto/sha256" "fmt" "io" "io/ioutil" @@ -22,7 +22,7 @@ import ( func bindataRead(data []byte, name string) ([]byte, error) { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } var buf bytes.Buffer @@ -30,7 +30,7 @@ func bindataRead(data []byte, name string) ([]byte, error) { clErr := gz.Close() if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } if clErr != nil { return nil, err @@ -40,8 +40,9 @@ func bindataRead(data []byte, name string) ([]byte, error) { } type asset struct { - bytes []byte - info os.FileInfo + bytes []byte + info os.FileInfo + digest [sha256.Size]byte } type bindataFileInfo struct { @@ -85,8 +86,8 @@ func _1557732988_initialize_dbDownSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1557732988_initialize_db.down.sql", size: 72, mode: os.FileMode(420), modTime: time.Unix(1560418002, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "1557732988_initialize_db.down.sql", size: 72, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x77, 0x40, 0x78, 0xb7, 0x71, 0x3c, 0x20, 0x3b, 0xc9, 0xb, 0x2f, 0x49, 0xe4, 0xff, 0x1c, 0x84, 0x54, 0xa1, 0x30, 0xe3, 0x90, 0xf8, 0x73, 0xda, 0xb0, 0x2a, 0xea, 0x8e, 0xf1, 0x82, 0xe7, 0xd2}} return a, nil } @@ -105,8 +106,8 @@ func _1557732988_initialize_dbUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "1557732988_initialize_db.up.sql", size: 234, mode: os.FileMode(420), modTime: time.Unix(1560418002, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "1557732988_initialize_db.up.sql", size: 234, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8f, 0xa, 0x31, 0xf, 0x94, 0xe, 0xd7, 0xd6, 0xaa, 0x22, 0xd6, 0x6c, 0x7a, 0xbc, 0xad, 0x6a, 0xed, 0x2e, 0x7a, 0xf0, 0x24, 0x81, 0x87, 0x14, 0xe, 0x1c, 0x8a, 0xf1, 0x45, 0xaf, 0x9e, 0x85}} return a, nil } @@ -125,8 +126,8 @@ func staticGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "static.go", size: 178, mode: os.FileMode(420), modTime: time.Unix(1560418002, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "static.go", size: 178, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xab, 0x8a, 0xf4, 0x27, 0x24, 0x9d, 0x2a, 0x1, 0x7b, 0x54, 0xea, 0xae, 0x4a, 0x35, 0x40, 0x92, 0xb5, 0xf9, 0xb3, 0x54, 0x3e, 0x3a, 0x1a, 0x2b, 0xae, 0xfb, 0x9e, 0x82, 0xeb, 0x4c, 0xf, 0x6}} return a, nil } @@ -134,8 +135,8 @@ func staticGo() (*asset, error) { // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) @@ -145,6 +146,12 @@ func Asset(name string) ([]byte, error) { return nil, fmt.Errorf("Asset %s not found", name) } +// AssetString returns the asset contents as a string (instead of a []byte). +func AssetString(name string) (string, error) { + data, err := Asset(name) + return string(data), err +} + // MustAsset is like Asset but panics when Asset would return an error. // It simplifies safe initialization of global variables. func MustAsset(name string) []byte { @@ -156,12 +163,18 @@ func MustAsset(name string) []byte { return a } +// MustAssetString is like AssetString but panics when Asset would return an +// error. It simplifies safe initialization of global variables. +func MustAssetString(name string) string { + return string(MustAsset(name)) +} + // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or // could not be loaded. func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) @@ -171,6 +184,33 @@ func AssetInfo(name string) (os.FileInfo, error) { return nil, fmt.Errorf("AssetInfo %s not found", name) } +// AssetDigest returns the digest of the file with the given name. It returns an +// error if the asset could not be found or the digest could not be loaded. +func AssetDigest(name string) ([sha256.Size]byte, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err) + } + return a.digest, nil + } + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name) +} + +// Digests returns a map of all known files and their checksums. +func Digests() (map[string][sha256.Size]byte, error) { + mp := make(map[string][sha256.Size]byte, len(_bindata)) + for name := range _bindata { + a, err := _bindata[name]() + if err != nil { + return nil, err + } + mp[name] = a.digest + } + return mp, nil +} + // AssetNames returns the names of the assets. func AssetNames() []string { names := make([]string, 0, len(_bindata)) @@ -183,7 +223,9 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ "1557732988_initialize_db.down.sql": _1557732988_initialize_dbDownSql, + "1557732988_initialize_db.up.sql": _1557732988_initialize_dbUpSql, + "static.go": staticGo, } @@ -196,15 +238,15 @@ var _bindata = map[string]func() (*asset, error){ // img/ // a.png // b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// then AssetDir("data") would return []string{"foo.txt", "img"}, +// AssetDir("data/img") would return []string{"a.png", "b.png"}, +// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") + canonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(canonicalName, "/") for _, p := range pathList { node = node.Children[p] if node == nil { @@ -226,13 +268,14 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "1557732988_initialize_db.down.sql": &bintree{_1557732988_initialize_dbDownSql, map[string]*bintree{}}, - "1557732988_initialize_db.up.sql": &bintree{_1557732988_initialize_dbUpSql, map[string]*bintree{}}, - "static.go": &bintree{staticGo, map[string]*bintree{}}, + "1557732988_initialize_db.up.sql": &bintree{_1557732988_initialize_dbUpSql, map[string]*bintree{}}, + "static.go": &bintree{staticGo, map[string]*bintree{}}, }} -// RestoreAsset restores an asset under the given directory +// RestoreAsset restores an asset under the given directory. func RestoreAsset(dir, name string) error { data, err := Asset(name) if err != nil { @@ -250,14 +293,10 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } -// RestoreAssets restores an asset under the given directory recursively +// RestoreAssets restores an asset under the given directory recursively. func RestoreAssets(dir, name string) error { children, err := AssetDir(name) // File @@ -275,7 +314,6 @@ func RestoreAssets(dir, name string) error { } func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) + canonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) } - diff --git a/params/config.go b/params/config.go index 8ba6a9eba..de0474a36 100644 --- a/params/config.go +++ b/params/config.go @@ -352,6 +352,10 @@ type NodeConfig struct { // PermissionsConfig extra configuration for permissions.Service. PermissionsConfig PermissionsConfig + // MailserversConfig extra configuration for mailservers.Service + // (persistent storage of user's mailserver records). + MailserversConfig MailserversConfig + // SwarmConfig extra configuration for Swarm and ENS SwarmConfig SwarmConfig `json:"SwarmConfig," validate:"structonly"` @@ -382,6 +386,11 @@ type PermissionsConfig struct { Enabled bool } +// MailserversConfig extra configuration for mailservers.Service. +type MailserversConfig struct { + Enabled bool +} + // ShhextConfig defines options used by shhext service. type ShhextConfig struct { PFSEnabled bool diff --git a/services/mailservers/README.md b/services/mailservers/README.md new file mode 100644 index 000000000..96b6052b1 --- /dev/null +++ b/services/mailservers/README.md @@ -0,0 +1,45 @@ +Mailservers Service +================ + +Mailservers service provides read/write API for `Mailserver` object +which stores details about user's mailservers. + +To enable this service, include `mailservers` in APIModules: + + +```json +{ + "MailserversConfig": { + "Enabled": true + }, + "APIModules": "mailservers" +} +``` + +API +--- + +Enabling service will expose three additional methods: + +#### mailservers_addMailserver + +Stores `Mailserver` in the database. +All fields are specified below: + +```json +{ + "id": "1", + "name": "my mailserver", + "address": "enode://...", + "password": "some-pass", + "fleet": "beta" +} +``` + +#### mailservers_getMailservers + +Reads all saved mailservers. + +#### mailservers_deleteMailserver + +Deletes a mailserver specified by an ID. diff --git a/services/mailservers/api.go b/services/mailservers/api.go new file mode 100644 index 000000000..aed2a063c --- /dev/null +++ b/services/mailservers/api.go @@ -0,0 +1,24 @@ +package mailservers + +import "context" + +func NewAPI(db *Database) *API { + return &API{db} +} + +// API is class with methods available over RPC. +type API struct { + db *Database +} + +func (a *API) AddMailserver(ctx context.Context, m Mailserver) error { + return a.db.Add(m) +} + +func (a *API) GetMailservers(ctx context.Context) ([]Mailserver, error) { + return a.db.Mailservers() +} + +func (a *API) DeleteMailserver(ctx context.Context, id string) error { + return a.db.Delete(id) +} diff --git a/services/mailservers/api_test.go b/services/mailservers/api_test.go new file mode 100644 index 000000000..bcc2573f7 --- /dev/null +++ b/services/mailservers/api_test.go @@ -0,0 +1,56 @@ +package mailservers + +import ( + "context" + "io/ioutil" + "os" + "testing" + + "github.com/status-im/status-go/appdatabase" + "github.com/stretchr/testify/require" +) + +func setupTestDB(t *testing.T) (*Database, func()) { + tmpfile, err := ioutil.TempFile("", "mailservers-service") + require.NoError(t, err) + db, err := appdatabase.InitializeDB(tmpfile.Name(), "mailservers-tests") + require.NoError(t, err) + return NewDB(db), func() { + require.NoError(t, db.Close()) + require.NoError(t, os.Remove(tmpfile.Name())) + } +} + +func TestAddGetDeleteMailserver(t *testing.T) { + db, close := setupTestDB(t) + defer close() + api := &API{db: db} + testMailserver := Mailserver{ + ID: "mailserver001", + Name: "My Mailserver", + Address: "enode://...", + Fleet: "beta", + } + testMailserverWithPassword := testMailserver + testMailserverWithPassword.ID = "mailserver002" + testMailserverWithPassword.Password = "test-pass" + + err := api.AddMailserver(context.Background(), testMailserver) + require.NoError(t, err) + err = api.AddMailserver(context.Background(), testMailserverWithPassword) + require.NoError(t, err) + + mailservers, err := api.GetMailservers(context.Background()) + require.NoError(t, err) + require.EqualValues(t, []Mailserver{testMailserver, testMailserverWithPassword}, mailservers) + + err = api.DeleteMailserver(context.Background(), testMailserver.ID) + require.NoError(t, err) + // Verify they was deleted. + mailservers, err = api.GetMailservers(context.Background()) + require.NoError(t, err) + require.EqualValues(t, []Mailserver{testMailserverWithPassword}, mailservers) + // Delete non-existing mailserver. + err = api.DeleteMailserver(context.Background(), "other-id") + require.NoError(t, err) +} diff --git a/services/mailservers/database.go b/services/mailservers/database.go new file mode 100644 index 000000000..014854f4b --- /dev/null +++ b/services/mailservers/database.go @@ -0,0 +1,82 @@ +package mailservers + +import "database/sql" + +type Mailserver struct { + ID string `json:"id"` + Name string `json:"name"` + Address string `json:"address"` + Password string `json:"password,omitempty"` + Fleet string `json:"fleet"` +} + +func (m Mailserver) nullablePassword() (val sql.NullString) { + if m.Password != "" { + val.String = m.Password + val.Valid = true + } + return +} + +// Database sql wrapper for operations with mailserver objects. +type Database struct { + db *sql.DB +} + +func NewDB(db *sql.DB) *Database { + return &Database{db: db} +} + +func (d *Database) Add(mailserver Mailserver) error { + _, err := d.db.Exec(`INSERT OR REPLACE INTO mailservers( + id, + name, + address, + password, + fleet + ) VALUES (?, ?, ?, ?, ?)`, + mailserver.ID, + mailserver.Name, + mailserver.Address, + mailserver.nullablePassword(), + mailserver.Fleet, + ) + return err +} + +func (d *Database) Mailservers() ([]Mailserver, error) { + var result []Mailserver + + rows, err := d.db.Query(`SELECT id, name, address, password, fleet FROM mailservers`) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var ( + m Mailserver + password sql.NullString + ) + if err := rows.Scan( + &m.ID, + &m.Name, + &m.Address, + &password, + &m.Fleet, + ); err != nil { + return nil, err + } + if password.Valid { + m.Password = password.String + } + result = append(result, m) + } + + return result, nil +} + +func (d *Database) Delete(id string) error { + _, err := d.db.Exec(`DELETE FROM mailservers WHERE id = ?`, id) + return err +} diff --git a/services/mailservers/service.go b/services/mailservers/service.go new file mode 100644 index 000000000..7e11a7c11 --- /dev/null +++ b/services/mailservers/service.go @@ -0,0 +1,37 @@ +package mailservers + +import ( + "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/rpc" +) + +func NewService(db *Database) *Service { + return &Service{db: db} +} + +type Service struct { + db *Database +} + +func (s *Service) Start(*p2p.Server) error { + return nil +} + +func (s *Service) Stop() error { + return nil +} + +func (s *Service) APIs() []rpc.API { + return []rpc.API{ + { + Namespace: "mailservers", + Version: "0.1.0", + Service: NewAPI(s.db), + Public: true, + }, + } +} + +func (s *Service) Protocols() []p2p.Protocol { + return nil +} diff --git a/static/bindata.go b/static/bindata.go index b3d46c54f..77c7f793b 100644 --- a/static/bindata.go +++ b/static/bindata.go @@ -1,26 +1,26 @@ -// Code generated by go-bindata. +// Code generated by go-bindata. DO NOT EDIT. // sources: -// ../config/README.md -// ../config/cli/fleet-eth.beta.json -// ../config/cli/fleet-eth.staging.json -// ../config/cli/fleet-eth.test.json -// ../config/cli/les-enabled.json -// ../config/cli/mailserver-enabled.json -// ../config/status-chain-genesis.json -// keys/bootnode.key -// keys/firebaseauthkey -// keys/test-account1-status-chain.pk -// keys/test-account1.pk -// keys/test-account2-status-chain.pk -// keys/test-account2.pk -// keys/test-account3-before-eip55.pk -// DO NOT EDIT! +// ../config/README.md (3.33kB) +// ../config/cli/fleet-eth.beta.json (3.261kB) +// ../config/cli/fleet-eth.staging.json (1.862kB) +// ../config/cli/fleet-eth.test.json (1.543kB) +// ../config/cli/les-enabled.json (58B) +// ../config/cli/mailserver-enabled.json (176B) +// ../config/status-chain-genesis.json (612B) +// keys/bootnode.key (65B) +// keys/firebaseauthkey (153B) +// keys/test-account1-status-chain.pk (489B) +// keys/test-account1.pk (491B) +// keys/test-account2-status-chain.pk (489B) +// keys/test-account2.pk (491B) +// keys/test-account3-before-eip55.pk (489B) package static import ( "bytes" "compress/gzip" + "crypto/sha256" "fmt" "io" "io/ioutil" @@ -33,7 +33,7 @@ import ( func bindataRead(data []byte, name string) ([]byte, error) { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } var buf bytes.Buffer @@ -41,7 +41,7 @@ func bindataRead(data []byte, name string) ([]byte, error) { clErr := gz.Close() if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } if clErr != nil { return nil, err @@ -51,8 +51,9 @@ func bindataRead(data []byte, name string) ([]byte, error) { } type asset struct { - bytes []byte - info os.FileInfo + bytes []byte + info os.FileInfo + digest [sha256.Size]byte } type bindataFileInfo struct { @@ -96,8 +97,8 @@ func ConfigReadmeMd() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/README.md", size: 3330, mode: os.FileMode(420), modTime: time.Unix(1560418002, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/README.md", size: 3330, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x65, 0xb9, 0xf5, 0x6, 0xbe, 0x7d, 0x85, 0x3b, 0x8, 0xbc, 0x5c, 0x71, 0x85, 0x19, 0xd1, 0xde, 0x38, 0xb5, 0xe9, 0x90, 0x5c, 0x45, 0xb2, 0xa5, 0x8a, 0x91, 0xee, 0xeb, 0x1e, 0xb4, 0xa9, 0x8f}} return a, nil } @@ -116,8 +117,8 @@ func ConfigCliFleetEthBetaJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3261, mode: os.FileMode(420), modTime: time.Unix(1548939502, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/cli/fleet-eth.beta.json", size: 3261, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x2b, 0xae, 0x42, 0x4b, 0xa4, 0xd9, 0x2, 0x69, 0x99, 0x29, 0x7e, 0x1, 0x4e, 0xd9, 0x58, 0x84, 0x28, 0x3a, 0x81, 0xc4, 0xde, 0x1d, 0xea, 0x51, 0xc8, 0x21, 0xff, 0x7b, 0xff, 0x23, 0x1c, 0x16}} return a, nil } @@ -136,8 +137,8 @@ func ConfigCliFleetEthStagingJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1862, mode: os.FileMode(420), modTime: time.Unix(1548939502, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1862, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xae, 0x85, 0xa1, 0x10, 0x16, 0x87, 0x10, 0x1c, 0xc3, 0xf4, 0xc7, 0xc, 0x2e, 0x51, 0xb7, 0x3, 0x61, 0x16, 0x99, 0x84, 0x3d, 0x5d, 0x82, 0x62, 0xfb, 0xf4, 0x5e, 0x19, 0xda, 0xb9, 0xaa, 0xc4}} return a, nil } @@ -156,8 +157,8 @@ func ConfigCliFleetEthTestJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1543, mode: os.FileMode(420), modTime: time.Unix(1548939502, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1543, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x68, 0xef, 0x71, 0xa1, 0x38, 0x37, 0xf0, 0x0, 0xbb, 0x95, 0x26, 0x2a, 0x2a, 0x65, 0x98, 0xfe, 0xe5, 0x3f, 0xbf, 0xb, 0x68, 0xa6, 0xb5, 0xa4, 0x10, 0xc1, 0x4b, 0x67, 0xb4, 0x4e, 0x32, 0xc0}} return a, nil } @@ -176,8 +177,8 @@ func ConfigCliLesEnabledJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(420), modTime: time.Unix(1541418081, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/cli/les-enabled.json", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x7e, 0xee, 0x27, 0xa7, 0x74, 0xa0, 0x46, 0xa1, 0x41, 0xed, 0x4d, 0x16, 0x5b, 0xf3, 0xf0, 0x7c, 0xc8, 0x2f, 0x6f, 0x47, 0xa4, 0xbb, 0x5f, 0x43, 0x33, 0xd, 0x9, 0x9d, 0xea, 0x9e, 0x15, 0xee}} return a, nil } @@ -196,8 +197,8 @@ func ConfigCliMailserverEnabledJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 176, mode: os.FileMode(420), modTime: time.Unix(1541418081, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/cli/mailserver-enabled.json", size: 176, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0xec, 0x81, 0x8b, 0x99, 0xb6, 0xdb, 0xc0, 0x8b, 0x46, 0x97, 0x96, 0xc7, 0x58, 0x30, 0x33, 0xef, 0x54, 0x25, 0x87, 0x7b, 0xb9, 0x94, 0x6b, 0x18, 0xa4, 0x5b, 0x58, 0x67, 0x7c, 0x44, 0xa6}} return a, nil } @@ -216,8 +217,8 @@ func ConfigStatusChainGenesisJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(420), modTime: time.Unix(1541418081, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "../config/status-chain-genesis.json", size: 612, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb, 0xf0, 0xc, 0x1, 0x95, 0x65, 0x6, 0x55, 0x48, 0x8f, 0x83, 0xa0, 0xb4, 0x81, 0xda, 0xad, 0x30, 0x6d, 0xb2, 0x78, 0x1b, 0x26, 0x4, 0x13, 0x12, 0x9, 0x6, 0xae, 0x3a, 0x2c, 0x1, 0x71}} return a, nil } @@ -236,8 +237,8 @@ func keysBootnodeKey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/bootnode.key", size: 65, mode: os.FileMode(420), modTime: time.Unix(1539606161, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/bootnode.key", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x31, 0xcf, 0x27, 0xd4, 0x96, 0x2e, 0x32, 0xcd, 0x58, 0x96, 0x2a, 0xe5, 0x8c, 0xa0, 0xf1, 0x73, 0x1f, 0xd6, 0xd6, 0x8b, 0xb, 0x73, 0xd3, 0x2c, 0x84, 0x1a, 0x56, 0xa4, 0x74, 0xb6, 0x95, 0x20}} return a, nil } @@ -256,8 +257,8 @@ func keysFirebaseauthkey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(420), modTime: time.Unix(1536843582, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/firebaseauthkey", size: 153, mode: os.FileMode(0644), modTime: time.Unix(1560062905, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe, 0x69, 0x23, 0x64, 0x7d, 0xf9, 0x14, 0x37, 0x6f, 0x2b, 0x1, 0xf0, 0xb0, 0xa4, 0xb2, 0xd0, 0x18, 0xcd, 0xf9, 0xeb, 0x57, 0xa3, 0xfd, 0x79, 0x25, 0xa7, 0x9c, 0x3, 0xce, 0x26, 0xec, 0xe1}} return a, nil } @@ -276,8 +277,8 @@ func keysTestAccount1StatusChainPk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account1-status-chain.pk", size: 489, mode: os.FileMode(420), modTime: time.Unix(1539606161, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/test-account1-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8f, 0xba, 0x35, 0x1, 0x2b, 0x9d, 0xad, 0xf0, 0x2d, 0x3c, 0x4d, 0x6, 0xb5, 0x22, 0x2, 0x47, 0xd4, 0x1c, 0xf4, 0x31, 0x2f, 0xb, 0x5b, 0x27, 0x5d, 0x43, 0x97, 0x58, 0x2d, 0xf0, 0xe1, 0xbe}} return a, nil } @@ -296,8 +297,8 @@ func keysTestAccount1Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account1.pk", size: 491, mode: os.FileMode(420), modTime: time.Unix(1539606161, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/test-account1.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0x43, 0xc2, 0xf4, 0x8c, 0xc6, 0x64, 0x25, 0x8c, 0x7, 0x8c, 0xa8, 0x89, 0x2b, 0x7b, 0x9b, 0x4f, 0x81, 0xcb, 0xce, 0x3d, 0xef, 0x82, 0x9c, 0x27, 0x27, 0xa9, 0xc5, 0x46, 0x70, 0x30, 0x38}} return a, nil } @@ -316,8 +317,8 @@ func keysTestAccount2StatusChainPk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account2-status-chain.pk", size: 489, mode: os.FileMode(420), modTime: time.Unix(1539606161, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/test-account2-status-chain.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0xf8, 0x5c, 0xe9, 0x92, 0x96, 0x2d, 0x88, 0x2b, 0x8e, 0x42, 0x3f, 0xa4, 0x93, 0x6c, 0xad, 0xe9, 0xc0, 0x1b, 0x8a, 0x8, 0x8c, 0x5e, 0x7a, 0x84, 0xa2, 0xf, 0x9f, 0x77, 0x58, 0x2c, 0x2c}} return a, nil } @@ -336,8 +337,8 @@ func keysTestAccount2Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account2.pk", size: 491, mode: os.FileMode(420), modTime: time.Unix(1539606161, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/test-account2.pk", size: 491, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9f, 0x72, 0xd5, 0x95, 0x5c, 0x5a, 0x99, 0x9d, 0x2f, 0x21, 0x83, 0xd7, 0x10, 0x17, 0x4a, 0x3d, 0x65, 0xc9, 0x26, 0x1a, 0x2c, 0x9d, 0x65, 0x63, 0xd2, 0xa0, 0xfc, 0x7c, 0x0, 0x87, 0x38, 0x9f}} return a, nil } @@ -356,8 +357,8 @@ func keysTestAccount3BeforeEip55Pk() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "keys/test-account3-before-eip55.pk", size: 489, mode: os.FileMode(420), modTime: time.Unix(1539606161, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "keys/test-account3-before-eip55.pk", size: 489, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x81, 0x40, 0x56, 0xc1, 0x5e, 0x10, 0x6e, 0x28, 0x15, 0x3, 0x4e, 0xc4, 0xc4, 0x71, 0x4d, 0x16, 0x99, 0xcc, 0x1b, 0x63, 0xee, 0x10, 0x20, 0xe4, 0x59, 0x52, 0x3f, 0xc0, 0xad, 0x15, 0x13, 0x72}} return a, nil } @@ -365,8 +366,8 @@ func keysTestAccount3BeforeEip55Pk() (*asset, error) { // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) @@ -376,6 +377,12 @@ func Asset(name string) ([]byte, error) { return nil, fmt.Errorf("Asset %s not found", name) } +// AssetString returns the asset contents as a string (instead of a []byte). +func AssetString(name string) (string, error) { + data, err := Asset(name) + return string(data), err +} + // MustAsset is like Asset but panics when Asset would return an error. // It simplifies safe initialization of global variables. func MustAsset(name string) []byte { @@ -387,12 +394,18 @@ func MustAsset(name string) []byte { return a } +// MustAssetString is like AssetString but panics when Asset would return an +// error. It simplifies safe initialization of global variables. +func MustAssetString(name string) string { + return string(MustAsset(name)) +} + // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or // could not be loaded. func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) @@ -402,6 +415,33 @@ func AssetInfo(name string) (os.FileInfo, error) { return nil, fmt.Errorf("AssetInfo %s not found", name) } +// AssetDigest returns the digest of the file with the given name. It returns an +// error if the asset could not be found or the digest could not be loaded. +func AssetDigest(name string) ([sha256.Size]byte, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err) + } + return a.digest, nil + } + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name) +} + +// Digests returns a map of all known files and their checksums. +func Digests() (map[string][sha256.Size]byte, error) { + mp := make(map[string][sha256.Size]byte, len(_bindata)) + for name := range _bindata { + a, err := _bindata[name]() + if err != nil { + return nil, err + } + mp[name] = a.digest + } + return mp, nil +} + // AssetNames returns the names of the assets. func AssetNames() []string { names := make([]string, 0, len(_bindata)) @@ -414,18 +454,31 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ "../config/README.md": ConfigReadmeMd, + "../config/cli/fleet-eth.beta.json": ConfigCliFleetEthBetaJson, + "../config/cli/fleet-eth.staging.json": ConfigCliFleetEthStagingJson, + "../config/cli/fleet-eth.test.json": ConfigCliFleetEthTestJson, + "../config/cli/les-enabled.json": ConfigCliLesEnabledJson, + "../config/cli/mailserver-enabled.json": ConfigCliMailserverEnabledJson, + "../config/status-chain-genesis.json": ConfigStatusChainGenesisJson, + "keys/bootnode.key": keysBootnodeKey, + "keys/firebaseauthkey": keysFirebaseauthkey, + "keys/test-account1-status-chain.pk": keysTestAccount1StatusChainPk, + "keys/test-account1.pk": keysTestAccount1Pk, + "keys/test-account2-status-chain.pk": keysTestAccount2StatusChainPk, + "keys/test-account2.pk": keysTestAccount2Pk, + "keys/test-account3-before-eip55.pk": keysTestAccount3BeforeEip55Pk, } @@ -438,15 +491,15 @@ var _bindata = map[string]func() (*asset, error){ // img/ // a.png // b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// then AssetDir("data") would return []string{"foo.txt", "img"}, +// AssetDir("data/img") would return []string{"a.png", "b.png"}, +// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") + canonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(canonicalName, "/") for _, p := range pathList { node = node.Children[p] if node == nil { @@ -468,32 +521,33 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "..": &bintree{nil, map[string]*bintree{ "config": &bintree{nil, map[string]*bintree{ "README.md": &bintree{ConfigReadmeMd, map[string]*bintree{}}, "cli": &bintree{nil, map[string]*bintree{ - "fleet-eth.beta.json": &bintree{ConfigCliFleetEthBetaJson, map[string]*bintree{}}, - "fleet-eth.staging.json": &bintree{ConfigCliFleetEthStagingJson, map[string]*bintree{}}, - "fleet-eth.test.json": &bintree{ConfigCliFleetEthTestJson, map[string]*bintree{}}, - "les-enabled.json": &bintree{ConfigCliLesEnabledJson, map[string]*bintree{}}, + "fleet-eth.beta.json": &bintree{ConfigCliFleetEthBetaJson, map[string]*bintree{}}, + "fleet-eth.staging.json": &bintree{ConfigCliFleetEthStagingJson, map[string]*bintree{}}, + "fleet-eth.test.json": &bintree{ConfigCliFleetEthTestJson, map[string]*bintree{}}, + "les-enabled.json": &bintree{ConfigCliLesEnabledJson, map[string]*bintree{}}, "mailserver-enabled.json": &bintree{ConfigCliMailserverEnabledJson, map[string]*bintree{}}, }}, "status-chain-genesis.json": &bintree{ConfigStatusChainGenesisJson, map[string]*bintree{}}, }}, }}, "keys": &bintree{nil, map[string]*bintree{ - "bootnode.key": &bintree{keysBootnodeKey, map[string]*bintree{}}, - "firebaseauthkey": &bintree{keysFirebaseauthkey, map[string]*bintree{}}, + "bootnode.key": &bintree{keysBootnodeKey, map[string]*bintree{}}, + "firebaseauthkey": &bintree{keysFirebaseauthkey, map[string]*bintree{}}, "test-account1-status-chain.pk": &bintree{keysTestAccount1StatusChainPk, map[string]*bintree{}}, - "test-account1.pk": &bintree{keysTestAccount1Pk, map[string]*bintree{}}, + "test-account1.pk": &bintree{keysTestAccount1Pk, map[string]*bintree{}}, "test-account2-status-chain.pk": &bintree{keysTestAccount2StatusChainPk, map[string]*bintree{}}, - "test-account2.pk": &bintree{keysTestAccount2Pk, map[string]*bintree{}}, + "test-account2.pk": &bintree{keysTestAccount2Pk, map[string]*bintree{}}, "test-account3-before-eip55.pk": &bintree{keysTestAccount3BeforeEip55Pk, map[string]*bintree{}}, }}, }} -// RestoreAsset restores an asset under the given directory +// RestoreAsset restores an asset under the given directory. func RestoreAsset(dir, name string) error { data, err := Asset(name) if err != nil { @@ -511,14 +565,10 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } -// RestoreAssets restores an asset under the given directory recursively +// RestoreAssets restores an asset under the given directory recursively. func RestoreAssets(dir, name string) error { children, err := AssetDir(name) // File @@ -536,7 +586,6 @@ func RestoreAssets(dir, name string) error { } func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) + canonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) } - diff --git a/t/bindata.go b/t/bindata.go index f921feb9d..adac4b4c9 100644 --- a/t/bindata.go +++ b/t/bindata.go @@ -1,15 +1,15 @@ -// Code generated by go-bindata. +// Code generated by go-bindata. DO NOT EDIT. // sources: -// config/public-chain-accounts.json -// config/status-chain-accounts.json -// config/test-data.json -// DO NOT EDIT! +// config/public-chain-accounts.json (307B) +// config/status-chain-accounts.json (543B) +// config/test-data.json (84B) package t import ( "bytes" "compress/gzip" + "crypto/sha256" "fmt" "io" "io/ioutil" @@ -22,7 +22,7 @@ import ( func bindataRead(data []byte, name string) ([]byte, error) { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } var buf bytes.Buffer @@ -30,7 +30,7 @@ func bindataRead(data []byte, name string) ([]byte, error) { clErr := gz.Close() if err != nil { - return nil, fmt.Errorf("Read %q: %v", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } if clErr != nil { return nil, err @@ -40,8 +40,9 @@ func bindataRead(data []byte, name string) ([]byte, error) { } type asset struct { - bytes []byte - info os.FileInfo + bytes []byte + info os.FileInfo + digest [sha256.Size]byte } type bindataFileInfo struct { @@ -85,8 +86,8 @@ func configPublicChainAccountsJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/public-chain-accounts.json", size: 307, mode: os.FileMode(420), modTime: time.Unix(1560418002, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "config/public-chain-accounts.json", size: 307, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x76, 0x5d, 0xc0, 0xfe, 0x57, 0x50, 0x18, 0xec, 0x2d, 0x61, 0x1b, 0xa9, 0x81, 0x11, 0x5f, 0x77, 0xf7, 0xb6, 0x67, 0x82, 0x1, 0x40, 0x68, 0x9d, 0xc5, 0x41, 0xaf, 0xce, 0x43, 0x81, 0x92, 0x96}} return a, nil } @@ -105,8 +106,8 @@ func configStatusChainAccountsJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/status-chain-accounts.json", size: 543, mode: os.FileMode(420), modTime: time.Unix(1560418002, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "config/status-chain-accounts.json", size: 543, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8e, 0xb3, 0x61, 0x51, 0x70, 0x3c, 0x12, 0x3e, 0xf1, 0x1c, 0x81, 0xfb, 0x9a, 0x7c, 0xe3, 0x63, 0xd0, 0x8f, 0x12, 0xc5, 0x2d, 0xf4, 0xea, 0x27, 0x33, 0xef, 0xca, 0xf9, 0x3f, 0x72, 0x44, 0xbf}} return a, nil } @@ -125,8 +126,8 @@ func configTestDataJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "config/test-data.json", size: 84, mode: os.FileMode(420), modTime: time.Unix(1541418081, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "config/test-data.json", size: 84, mode: os.FileMode(0644), modTime: time.Unix(1566753958, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xce, 0x9d, 0x80, 0xf5, 0x87, 0xfa, 0x57, 0x1d, 0xa1, 0xd5, 0x7a, 0x10, 0x3, 0xac, 0xd7, 0xf4, 0x64, 0x32, 0x96, 0x2b, 0xb7, 0x21, 0xb7, 0xa6, 0x80, 0x40, 0xe9, 0x65, 0xe3, 0xd6, 0xbd, 0x40}} return a, nil } @@ -134,8 +135,8 @@ func configTestDataJson() (*asset, error) { // It returns an error if the asset could not be found or // could not be loaded. func Asset(name string) ([]byte, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) @@ -145,6 +146,12 @@ func Asset(name string) ([]byte, error) { return nil, fmt.Errorf("Asset %s not found", name) } +// AssetString returns the asset contents as a string (instead of a []byte). +func AssetString(name string) (string, error) { + data, err := Asset(name) + return string(data), err +} + // MustAsset is like Asset but panics when Asset would return an error. // It simplifies safe initialization of global variables. func MustAsset(name string) []byte { @@ -156,12 +163,18 @@ func MustAsset(name string) []byte { return a } +// MustAssetString is like AssetString but panics when Asset would return an +// error. It simplifies safe initialization of global variables. +func MustAssetString(name string) string { + return string(MustAsset(name)) +} + // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or // could not be loaded. func AssetInfo(name string) (os.FileInfo, error) { - cannonicalName := strings.Replace(name, "\\", "/", -1) - if f, ok := _bindata[cannonicalName]; ok { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { a, err := f() if err != nil { return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) @@ -171,6 +184,33 @@ func AssetInfo(name string) (os.FileInfo, error) { return nil, fmt.Errorf("AssetInfo %s not found", name) } +// AssetDigest returns the digest of the file with the given name. It returns an +// error if the asset could not be found or the digest could not be loaded. +func AssetDigest(name string) ([sha256.Size]byte, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err) + } + return a.digest, nil + } + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name) +} + +// Digests returns a map of all known files and their checksums. +func Digests() (map[string][sha256.Size]byte, error) { + mp := make(map[string][sha256.Size]byte, len(_bindata)) + for name := range _bindata { + a, err := _bindata[name]() + if err != nil { + return nil, err + } + mp[name] = a.digest + } + return mp, nil +} + // AssetNames returns the names of the assets. func AssetNames() []string { names := make([]string, 0, len(_bindata)) @@ -183,7 +223,9 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ "config/public-chain-accounts.json": configPublicChainAccountsJson, + "config/status-chain-accounts.json": configStatusChainAccountsJson, + "config/test-data.json": configTestDataJson, } @@ -196,15 +238,15 @@ var _bindata = map[string]func() (*asset, error){ // img/ // a.png // b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// then AssetDir("data") would return []string{"foo.txt", "img"}, +// AssetDir("data/img") would return []string{"a.png", "b.png"}, +// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree if len(name) != 0 { - cannonicalName := strings.Replace(name, "\\", "/", -1) - pathList := strings.Split(cannonicalName, "/") + canonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(canonicalName, "/") for _, p := range pathList { node = node.Children[p] if node == nil { @@ -226,15 +268,16 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "config": &bintree{nil, map[string]*bintree{ "public-chain-accounts.json": &bintree{configPublicChainAccountsJson, map[string]*bintree{}}, "status-chain-accounts.json": &bintree{configStatusChainAccountsJson, map[string]*bintree{}}, - "test-data.json": &bintree{configTestDataJson, map[string]*bintree{}}, + "test-data.json": &bintree{configTestDataJson, map[string]*bintree{}}, }}, }} -// RestoreAsset restores an asset under the given directory +// RestoreAsset restores an asset under the given directory. func RestoreAsset(dir, name string) error { data, err := Asset(name) if err != nil { @@ -252,14 +295,10 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } -// RestoreAssets restores an asset under the given directory recursively +// RestoreAssets restores an asset under the given directory recursively. func RestoreAssets(dir, name string) error { children, err := AssetDir(name) // File @@ -277,7 +316,6 @@ func RestoreAssets(dir, name string) error { } func _filePath(dir, name string) string { - cannonicalName := strings.Replace(name, "\\", "/", -1) - return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) + canonicalName := strings.Replace(name, "\\", "/", -1) + return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...) } -