Search Apps Documentation Source Content File Folder Download Copy Actions Download

store.gno

0.64 Kb · 32 lines
 1package ulnbase
 2
 3import (
 4	"encoding/binary"
 5
 6	"gno.land/p/nt/avl/v0"
 7)
 8
 9type configStore struct {
10	tree avl.Tree
11}
12
13func (s *configStore) get(oapp address, remoteEid uint32) (*UlnConfig, bool) {
14	key := ulnConfigKey(oapp, remoteEid)
15	v, ok := s.tree.Get(key)
16	if !ok {
17		return nil, false
18	}
19	return v.(*UlnConfig), true
20}
21
22func (s *configStore) set(oapp address, remoteEid uint32, config *UlnConfig) bool {
23	key := ulnConfigKey(oapp, remoteEid)
24	return s.tree.Set(key, config)
25}
26
27func ulnConfigKey(oapp address, remoteEid uint32) string {
28	bz := make([]byte, 4+len(oapp))
29	binary.BigEndian.PutUint32(bz, remoteEid)
30	copy(bz[4:], oapp)
31	return string(bz)
32}