Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flip keywords #678

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/blockchain_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/idena-network/idena-go/common/hexutil"
"github.com/idena-network/idena-go/core/mempool"
"github.com/idena-network/idena-go/ipfs"
"github.com/idena-network/idena-go/keywords"
"github.com/idena-network/idena-go/protocol"
"github.com/idena-network/idena-go/rlp"
"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -408,3 +409,7 @@ func convertToBlock(block *types.Block) *Block {
OfflineAddr: block.Header.OfflineAddr(),
}
}

func (api *BlockchainApi) KeyWord(index int) (keywords.Keyword, error) {
return keywords.Get(index)
}
1 change: 1 addition & 0 deletions keywords/generate-asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go-bindata -o keywords_gen.go -pkg=keywords keywords.json
29 changes: 29 additions & 0 deletions keywords/keywords.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package keywords

import (
"encoding/json"
"github.com/idena-network/idena-go/log"
"github.com/pkg/errors"
)

type Keyword struct {
Name string
Desc string
}

var list []Keyword

func init() {
list = make([]Keyword, 0, 3350)
data, _ := Asset("keywords.json")
if err := json.Unmarshal(data, &list); err != nil {
log.Warn("cannot parse keywords.json", "err", err)
}
}

func Get(index int) (Keyword, error) {
if index >= len(list) || index < 0 {
return Keyword{}, errors.New("index is out of range")
}
return list[index], nil
}
Loading