|
|
@ -14,14 +14,11 @@ |
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -nocompress -o 4byte.go -pkg fourbyte 4byte.json
|
|
|
|
|
|
|
|
//go:generate gofmt -s -w 4byte.go
|
|
|
|
|
|
|
|
//go:generate sh -c "sed 's#var __4byteJson#//nolint:misspell\\\n&#' 4byte.go > 4byte.go.tmp && mv 4byte.go.tmp 4byte.go"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Package fourbyte contains the 4byte database.
|
|
|
|
// Package fourbyte contains the 4byte database.
|
|
|
|
package fourbyte |
|
|
|
package fourbyte |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
_ "embed" |
|
|
|
"encoding/hex" |
|
|
|
"encoding/hex" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
@ -29,6 +26,9 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//go:embed 4byte.json
|
|
|
|
|
|
|
|
var embeddedJSON []byte |
|
|
|
|
|
|
|
|
|
|
|
// Database is a 4byte database with the possibility of maintaining an immutable
|
|
|
|
// Database is a 4byte database with the possibility of maintaining an immutable
|
|
|
|
// set (embedded) into the process and a mutable set (loaded and written to file).
|
|
|
|
// set (embedded) into the process and a mutable set (loaded and written to file).
|
|
|
|
type Database struct { |
|
|
|
type Database struct { |
|
|
@ -77,15 +77,12 @@ func NewWithFile(path string) (*Database, error) { |
|
|
|
db := &Database{make(map[string]string), make(map[string]string), path} |
|
|
|
db := &Database{make(map[string]string), make(map[string]string), path} |
|
|
|
db.customPath = path |
|
|
|
db.customPath = path |
|
|
|
|
|
|
|
|
|
|
|
blob, err := Asset("4byte.json") |
|
|
|
if err := json.Unmarshal(embeddedJSON, &db.embedded); err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := json.Unmarshal(blob, &db.embedded); err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
// Custom file may not exist. Will be created during save, if needed.
|
|
|
|
// Custom file may not exist. Will be created during save, if needed.
|
|
|
|
if _, err := os.Stat(path); err == nil { |
|
|
|
if _, err := os.Stat(path); err == nil { |
|
|
|
|
|
|
|
var blob []byte |
|
|
|
if blob, err = ioutil.ReadFile(path); err != nil { |
|
|
|
if blob, err = ioutil.ReadFile(path); err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|