func (sm *StringMap) Len() int {
	return len(sm.Map)
}
Len returns the number of elements in the map.
package nkn
import (
	"context"
	"crypto/rand"
	"crypto/sha256"
	"log"
	"math/big"
	mathRand "math/rand"
	"strings"
	"sync"
	"time"
	"github.com/nknorg/nkn/v2/common"
	"github.com/nknorg/nkn/v2/crypto"
	"github.com/nknorg/nkn/v2/pb"
	"github.com/nknorg/nkn/v2/program"
	"github.com/nknorg/nkn/v2/util/address"
	"github.com/nknorg/nkn/v2/vault"
)
const (
	AmountUnit = common.StorageFactor
)
var (
	zeroTime time.Time
)
type Account struct{ *vault.Account }
func NewAccount(seed []byte) (*Account, error) {
	var account *vault.Account
	var err error
	if len(seed) > 0 {
		account, err = vault.NewAccountWithSeed(seed)
	} else {
		account, err = vault.NewAccount()
	}
	if err != nil {
		return nil, err
	}
	_, err = account.ProgramHash.ToAddress()
	if err != nil {
		return nil, err
	}
	return &Account{account}, err
}
func (account *Account) Seed() []byte {
	return crypto.GetSeedFromPrivateKey(account.PrivKey())
}
func (account *Account) PubKey() []byte {
	return account.Account.PublicKey
}
func (account *Account) WalletAddress() string {
	addr, _ := account.ProgramHash.ToAddress()
	return addr
}
type Amount struct{ common.Fixed64 }
func NewAmount(s string) (*Amount, error) {
	fixed64, err := common.StringToFixed64(s)
	if err != nil {
		return nil, err
	}
	return &Amount{fixed64}, err
}
func (amount *Amount) ToFixed64() common.Fixed64 {
	if amount == nil {
		return 0
	}
	return amount.Fixed64
}
type StringArray struct{ elems []string }
func NewStringArray(elems ...string) *StringArray {
	return &StringArray{elems}
}
func NewStringArrayFromString(s string) *StringArray {
	return &StringArray{strings.Fields(s)}
}
func (sa *StringArray) Elems() []string {
	if sa == nil {
		return nil
	}
	return sa.elems
}
func (sa *StringArray) Len() int {
	return len(sa.Elems())
}
func (sa *StringArray) Append(s string) {
	sa.elems = append(sa.elems, s)
}
func (sa *StringArray) RandomElem() string {
	if sa.Len() == 0 {
		return ""
	}
	return sa.Elems()[mathRand.Intn(sa.Len())]
}
func (sa *StringArray) Join(separator string) string {
	if sa == nil {
		return ""
	}
	return strings.Join(sa.elems, separator)
}
type StringMapFunc interface{ OnVisit(string, string) bool }
type StringMap struct{ Map map[string]string }
func NewStringMap(m map[string]string) *StringMap {
	return &StringMap{m}
}
func NewStringMapWithSize(size int) *StringMap {
	return &StringMap{make(map[string]string, size)}
}
func (sm *StringMap) Get(key string) (string, error) {
	if value, ok := sm.Map[key]; ok {
		return value, nil
	}
	return "", ErrKeyNotInMap
}
func (sm *StringMap) Set(key, value string) {
	sm.Map[key] = value
}
func (sm *StringMap) Delete(key string) {
	delete(sm.Map, key)
}