namecoin

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

package namecoin is an extension of x/cash from weave, allowing more information for wallets and tokens.

Token tickers (currency code) must be registered before they can be used, and are associated with a human readable name, as well as a flexible number of significant figures.

Wallets also have a name associated with them, which must be unique and can be used to locate the wallet (secondary index).

Index

Constants

View Source
const (
	// BucketNameToken is where we store the token definitions
	BucketNameToken = "tkn"
	// DefaultSigFigs is the default for any new token
	DefaultSigFigs = 9
)
View Source
const (
	// BucketNameWallet is where we store the balances
	BucketNameWallet = "wllt"
	// IndexName is the index to query wallet by name
	IndexName = "name"
)

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)
View Source
var (
	// IsTokenName limits the human-readable names of the tokens,
	// subset of ASCII to avoid unicode tricks.
	IsTokenName = regexp.MustCompile(`^[A-Za-z0-9 \-_:]{3,32}$`).MatchString
	// IsWalletName is allowed names to attach to a wallet address
	IsWalletName = regexp.MustCompile(`^[a-z0-9_]{4,20}$`).MatchString
)

Functions

func AsTicker

func AsTicker(obj orm.Object) string

AsTicker safely extracts the ticker value from the object object

func BuildGenesis

func BuildGenesis(wallets []GenesisAccount,
	tokens []GenesisToken) (weave.Options, error)

BuildGenesis will create Options with the given the wallets and tokens

func NewController

func NewController() cash.Controller

NewController uses the default implementation for now.

TODO: better enforce token presence and sigfigs

func NewFeeDecorator

func NewFeeDecorator(auth x.Authenticator) weave.Decorator

NewFeeDecorator customizes cash/FeeDecorator to use our WalletBucket.

func NewSendHandler

func NewSendHandler(auth x.Authenticator) weave.Handler

NewSendHandler customizes cash/SendHandler to use our WalletBucket.

func NewSetNameHandler

func NewSetNameHandler(auth x.Authenticator, bucket NamedBucket) weave.Handler

NewSetNameHandler creates a handler that lets you set the name on a wallet one time.

func NewToken

func NewToken(ticker, name string, sigFigs int32) orm.Object

NewToken generates a new token object, using ticker as key

func NewTokenHandler

func NewTokenHandler(auth x.Authenticator, issuer weave.Address) weave.Handler

NewTokenHandler creates a handler that allows issuer to create new token types. If issuer is nil, anyone can create new tokens. TODO: check that permissioning???

func NewWallet

func NewWallet(key weave.Address) orm.Object

NewWallet creates an empty wallet with this address serves as an object for the bucket

func RegisterQuery

func RegisterQuery(qr weave.QueryRouter)

RegisterQuery will register wallets as "/wallets" and tokens as "/tokens".

func RegisterRoutes

func RegisterRoutes(r weave.Registry, auth x.Authenticator, issuer weave.Address)

RegisterRoutes will instantiate and register all handlers in this package.

func WalletWith

func WalletWith(key weave.Address, name string, coins ...*coin.Coin) (orm.Object, error)

WalletWith creates an wallet with a balance

Types

type GenesisAccount

type GenesisAccount struct {
	Address weave.Address `json:"address"`
	*Wallet
}

GenesisAccount is used to parse the json from genesis file use weave.Address, so address in hex, not base64

type GenesisToken

type GenesisToken struct {
	Ticker  string `json:"ticker"`
	Name    string `json:"name"`
	SigFigs int32  `json:"sig_figs"`
}

GenesisToken is used to describe a token in the genesis account

func ToGenesisToken

func ToGenesisToken(ticker string, token *Token) GenesisToken

ToGenesisToken converts internal structs to genesis file format

type Initializer

type Initializer struct{}

Initializer fulfils the InitStater interface to load data from the genesis file

func (Initializer) FromGenesis

func (Initializer) FromGenesis(opts weave.Options, db weave.KVStore) error

FromGenesis will parse initial account info from genesis and save it to the database

type Named

type Named interface {
	GetName() string
	SetName(string) error
}

Named is any object that allows getting/setting a string name the object should be able to validate if SetName is a valid

func AsNamed

func AsNamed(obj orm.Object) Named

AsNamed returns an object that has can get/set names

type NamedBucket

type NamedBucket interface {
	GetOrCreate(db weave.KVStore, key weave.Address) (orm.Object, error)
	Get(db weave.ReadOnlyKVStore, key []byte) (orm.Object, error)
	GetByName(db weave.KVStore, name string) (orm.Object, error)
	Save(db weave.KVStore, obj orm.Object) error
}

NamedBucket is a bucket that can handle object with Get/SetName The object it returns must support AsNamed (only checked runtime :()

type NewTokenMsg

type NewTokenMsg struct {
	Ticker  string `protobuf:"bytes,1,opt,name=ticker,proto3" json:"ticker,omitempty"`
	Name    string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	SigFigs int32  `protobuf:"varint,3,opt,name=sig_figs,json=sigFigs,proto3" json:"sig_figs,omitempty"`
}

NewTokenMsg will register a new token. This must not conflict with any existing ticker, and should be limited to privledged users.

func BuildTokenMsg

func BuildTokenMsg(ticker, name string, sigFigs int32) *NewTokenMsg

BuildTokenMsg is a compact constructor for *NewTokenMsg

func (*NewTokenMsg) Descriptor

func (*NewTokenMsg) Descriptor() ([]byte, []int)

func (*NewTokenMsg) GetName

func (m *NewTokenMsg) GetName() string

func (*NewTokenMsg) GetSigFigs

func (m *NewTokenMsg) GetSigFigs() int32

func (*NewTokenMsg) GetTicker

func (m *NewTokenMsg) GetTicker() string

func (*NewTokenMsg) Marshal

func (m *NewTokenMsg) Marshal() (dAtA []byte, err error)

func (*NewTokenMsg) MarshalTo

func (m *NewTokenMsg) MarshalTo(dAtA []byte) (int, error)

func (NewTokenMsg) Path

func (NewTokenMsg) Path() string

Path returns the routing path for this message

func (*NewTokenMsg) ProtoMessage

func (*NewTokenMsg) ProtoMessage()

func (*NewTokenMsg) Reset

func (m *NewTokenMsg) Reset()

func (*NewTokenMsg) Size

func (m *NewTokenMsg) Size() (n int)

func (*NewTokenMsg) String

func (m *NewTokenMsg) String() string

func (*NewTokenMsg) Unmarshal

func (m *NewTokenMsg) Unmarshal(dAtA []byte) error

func (*NewTokenMsg) Validate

func (t *NewTokenMsg) Validate() error

Validate makes sure that this is sensible

func (*NewTokenMsg) XXX_DiscardUnknown added in v0.12.0

func (m *NewTokenMsg) XXX_DiscardUnknown()

func (*NewTokenMsg) XXX_Marshal added in v0.12.0

func (m *NewTokenMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NewTokenMsg) XXX_Merge added in v0.12.0

func (m *NewTokenMsg) XXX_Merge(src proto.Message)

func (*NewTokenMsg) XXX_Size added in v0.12.0

func (m *NewTokenMsg) XXX_Size() int

func (*NewTokenMsg) XXX_Unmarshal added in v0.12.0

func (m *NewTokenMsg) XXX_Unmarshal(b []byte) error

type SetNameHandler

type SetNameHandler struct {
	// contains filtered or unexported fields
}

SetNameHandler will set a name for objects in this bucket.

func (SetNameHandler) Check

Check just verifies it is properly formed and returns the cost of executing it.

func (SetNameHandler) Deliver

Deliver moves the tokens from sender to receiver if all preconditions are met.

type SetWalletNameMsg

type SetWalletNameMsg struct {
	Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
	Name    string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
}

SetWalletNameMsg will set the name on an existing wallet. Can only be performed if the wallet name is empty.

func BuildSetNameMsg

func BuildSetNameMsg(addr weave.Address, name string) *SetWalletNameMsg

BuildSetNameMsg is a compact constructor for *SetWalletNameMsg

func (*SetWalletNameMsg) Descriptor

func (*SetWalletNameMsg) Descriptor() ([]byte, []int)

func (*SetWalletNameMsg) GetAddress

func (m *SetWalletNameMsg) GetAddress() []byte

func (*SetWalletNameMsg) GetName

func (m *SetWalletNameMsg) GetName() string

func (*SetWalletNameMsg) Marshal

func (m *SetWalletNameMsg) Marshal() (dAtA []byte, err error)

func (*SetWalletNameMsg) MarshalTo

func (m *SetWalletNameMsg) MarshalTo(dAtA []byte) (int, error)

func (SetWalletNameMsg) Path

func (SetWalletNameMsg) Path() string

Path returns the routing path for this message

func (*SetWalletNameMsg) ProtoMessage

func (*SetWalletNameMsg) ProtoMessage()

func (*SetWalletNameMsg) Reset

func (m *SetWalletNameMsg) Reset()

func (*SetWalletNameMsg) Size

func (m *SetWalletNameMsg) Size() (n int)

func (*SetWalletNameMsg) String

func (m *SetWalletNameMsg) String() string

func (*SetWalletNameMsg) Unmarshal

func (m *SetWalletNameMsg) Unmarshal(dAtA []byte) error

func (*SetWalletNameMsg) Validate

func (s *SetWalletNameMsg) Validate() error

Validate makes sure that this is sensible

func (*SetWalletNameMsg) XXX_DiscardUnknown added in v0.12.0

func (m *SetWalletNameMsg) XXX_DiscardUnknown()

func (*SetWalletNameMsg) XXX_Marshal added in v0.12.0

func (m *SetWalletNameMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SetWalletNameMsg) XXX_Merge added in v0.12.0

func (m *SetWalletNameMsg) XXX_Merge(src proto.Message)

func (*SetWalletNameMsg) XXX_Size added in v0.12.0

func (m *SetWalletNameMsg) XXX_Size() int

func (*SetWalletNameMsg) XXX_Unmarshal added in v0.12.0

func (m *SetWalletNameMsg) XXX_Unmarshal(b []byte) error

type TickerBucket

type TickerBucket interface {
	// GetOrCreate(db weave.KVStore, ticker string) (orm.Object, error)
	Get(db weave.KVStore, ticker string) (orm.Object, error)
	Save(db weave.KVStore, obj orm.Object) error
}

TickerBucket can save and query Tokens (or anything with tickers...)

type Token

type Token struct {
	Name    string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	SigFigs int32  `protobuf:"varint,3,opt,name=sig_figs,json=sigFigs,proto3" json:"sig_figs,omitempty"`
}

Token contains information about a registered currency

func AsToken

func AsToken(obj orm.Object) *Token

AsToken safely extracts a Token value from the object

func (*Token) Copy

func (t *Token) Copy() orm.CloneableData

Copy makes a new set with the same coins

func (*Token) Descriptor

func (*Token) Descriptor() ([]byte, []int)

func (*Token) GetName

func (m *Token) GetName() string

func (*Token) GetSigFigs

func (m *Token) GetSigFigs() int32

func (*Token) Marshal

func (m *Token) Marshal() (dAtA []byte, err error)

func (*Token) MarshalTo

func (m *Token) MarshalTo(dAtA []byte) (int, error)

func (*Token) ProtoMessage

func (*Token) ProtoMessage()

func (*Token) Reset

func (m *Token) Reset()

func (*Token) Size

func (m *Token) Size() (n int)

func (*Token) String

func (m *Token) String() string

func (*Token) Unmarshal

func (m *Token) Unmarshal(dAtA []byte) error

func (*Token) Validate

func (t *Token) Validate() error

Validate ensures the token is valid

func (*Token) XXX_DiscardUnknown added in v0.12.0

func (m *Token) XXX_DiscardUnknown()

func (*Token) XXX_Marshal added in v0.12.0

func (m *Token) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Token) XXX_Merge added in v0.12.0

func (m *Token) XXX_Merge(src proto.Message)

func (*Token) XXX_Size added in v0.12.0

func (m *Token) XXX_Size() int

func (*Token) XXX_Unmarshal added in v0.12.0

func (m *Token) XXX_Unmarshal(b []byte) error

type TokenBucket

type TokenBucket struct {
	orm.Bucket
}

TokenBucket is a type-safe wrapper around orm.Bucket

func NewTokenBucket

func NewTokenBucket() TokenBucket

NewTokenBucket initializes a TokenBucket with default name

func (TokenBucket) Get

func (b TokenBucket) Get(db weave.KVStore, ticker string) (orm.Object, error)

Get takes the token name and converts it to a byte key

func (TokenBucket) Save

func (b TokenBucket) Save(db weave.KVStore, obj orm.Object) error

Save enforces the proper type

type TokenHandler

type TokenHandler struct {
	// contains filtered or unexported fields
}

TokenHandler will handle creating new tokens.

func (TokenHandler) Check

Check just verifies it is properly formed and returns the cost of executing it.

func (TokenHandler) Deliver

func (h TokenHandler) Deliver(ctx weave.Context, db weave.KVStore, tx weave.Tx) (weave.DeliverResult, error)

Deliver moves the tokens from sender to receiver if all preconditions are met.

type Wallet

type Wallet struct {
	Coins []*coin.Coin `protobuf:"bytes,1,rep,name=coins,proto3" json:"coins,omitempty"`
	Name  string       `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
}

Wallet has a name and a set of coins

func AsWallet

func AsWallet(obj orm.Object) *Wallet

AsWallet safely extracts a Wallet value from the object

func (*Wallet) Copy

func (w *Wallet) Copy() orm.CloneableData

Copy makes a new set with the same coins

func (*Wallet) Descriptor

func (*Wallet) Descriptor() ([]byte, []int)

func (*Wallet) GetCoins

func (m *Wallet) GetCoins() []*coin.Coin

func (*Wallet) GetName

func (m *Wallet) GetName() string

func (*Wallet) Marshal

func (m *Wallet) Marshal() (dAtA []byte, err error)

func (*Wallet) MarshalTo

func (m *Wallet) MarshalTo(dAtA []byte) (int, error)

func (*Wallet) ProtoMessage

func (*Wallet) ProtoMessage()

func (*Wallet) Reset

func (m *Wallet) Reset()

func (*Wallet) SetCoins

func (w *Wallet) SetCoins(coins []*coin.Coin)

SetCoins lets us modify the wallet and satisfy Coinage to be compatible with x/cash

func (*Wallet) SetName

func (w *Wallet) SetName(name string) error

SetName verifies the name is valid and sets it on the wallet

func (*Wallet) Size

func (m *Wallet) Size() (n int)

func (*Wallet) String

func (m *Wallet) String() string

func (*Wallet) Unmarshal

func (m *Wallet) Unmarshal(dAtA []byte) error

func (*Wallet) Validate

func (w *Wallet) Validate() error

Validate requires that all coins are in alphabetical

func (*Wallet) XXX_DiscardUnknown added in v0.12.0

func (m *Wallet) XXX_DiscardUnknown()

func (*Wallet) XXX_Marshal added in v0.12.0

func (m *Wallet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Wallet) XXX_Merge added in v0.12.0

func (m *Wallet) XXX_Merge(src proto.Message)

func (*Wallet) XXX_Size added in v0.12.0

func (m *Wallet) XXX_Size() int

func (*Wallet) XXX_Unmarshal added in v0.12.0

func (m *Wallet) XXX_Unmarshal(b []byte) error

type WalletBucket

type WalletBucket struct {
	orm.Bucket
}

WalletBucket is a type-safe wrapper around orm.Bucket

func NewWalletBucket

func NewWalletBucket() WalletBucket

NewWalletBucket initializes a WalletBucket and sets up a unique index by name

func (WalletBucket) GetByName

func (b WalletBucket) GetByName(db weave.KVStore, name string) (orm.Object, error)

GetByName queries the wallet by secondary index on name, may return nil or a matching wallet

func (WalletBucket) GetOrCreate

func (b WalletBucket) GetOrCreate(db weave.KVStore, key weave.Address) (orm.Object, error)

GetOrCreate will return the token if found, or create one with the given name otherwise.

func (WalletBucket) Save

func (b WalletBucket) Save(db weave.KVStore, obj orm.Object) error

Save enforces the proper type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL