username

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Package username implements a register of names that point to any blockchain address.

Each username consist of a name and a domain. Username format is `<name>*<namespace>`, for example `alice*iov`. Each username is unique. Any number of usernames can point to the same location. A location is a blockchain ID and an address value that is specific to that network.

You can think of the functionality provided by this package similar to what domain name server does. This functionality is narrowed to blockchains only.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)

Functions

func NewTokenBucket

func NewTokenBucket() orm.ModelBucket

NewTokenBucket returns a ModelBucket instance limited to interacting with a Token model only. Only a valid Username instance should be used as a key. Alternatively tokens can be queried by owner.

func RegisterQuery

func RegisterQuery(qr weave.QueryRouter)

RegisterQuery expose tokens bucket to queries.

func RegisterRoutes

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

Types

type BlockchainAddress

type BlockchainAddress struct {
	// An arbitrary blockchain ID.
	BlockchainID string `protobuf:"bytes,1,opt,name=blockchain_id,json=blockchainId,proto3" json:"blockchain_id,omitempty"`
	// An address on the specified blockchain network. Address is not a
	// weave.Address as we cannot know what is the format of an address on the
	// chain that this token instance links to. Because we do not know the rules
	// to validate an address for any blockchain ID, this is an arbitrary bulk of
	// data.
	// It is more convinient to always use encoded representation of each address
	// and store it as a string. Using bytes while compact is not as comfortable
	// to use.
	Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
}

BlockchainAddress represents a blochain address. This structure clubs together blokchain ID together with an address on that network. It is used to point to an address on any blockchain network.

func (*BlockchainAddress) Clone

func (*BlockchainAddress) Descriptor

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

func (*BlockchainAddress) GetAddress

func (m *BlockchainAddress) GetAddress() string

func (*BlockchainAddress) GetBlockchainID

func (m *BlockchainAddress) GetBlockchainID() string

func (*BlockchainAddress) Marshal

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

func (*BlockchainAddress) MarshalTo

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

func (*BlockchainAddress) ProtoMessage

func (*BlockchainAddress) ProtoMessage()

func (*BlockchainAddress) Reset

func (m *BlockchainAddress) Reset()

func (*BlockchainAddress) Size

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

func (*BlockchainAddress) String

func (m *BlockchainAddress) String() string

func (*BlockchainAddress) Unmarshal

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

func (*BlockchainAddress) Validate

func (ba *BlockchainAddress) Validate() error

func (*BlockchainAddress) XXX_DiscardUnknown

func (m *BlockchainAddress) XXX_DiscardUnknown()

func (*BlockchainAddress) XXX_Marshal

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

func (*BlockchainAddress) XXX_Merge

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

func (*BlockchainAddress) XXX_Size

func (m *BlockchainAddress) XXX_Size() int

func (*BlockchainAddress) XXX_Unmarshal

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

type ChangeTokenTargetsMsg

type ChangeTokenTargetsMsg struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Username is the unique name of the token, for example alice*iov
	Username Username `protobuf:"bytes,2,opt,name=username,proto3,casttype=Username" json:"username,omitempty"`
	// New targets is a list of blockchain addresses that this token should point
	// to after the change. Old list is overwritten with what is provided.
	NewTargets []BlockchainAddress `protobuf:"bytes,3,rep,name=new_targets,json=newTargets,proto3" json:"new_targets"`
}

ChangeTokenTargetsMsg is a request to change the address that this token points to. Only the owner of a token can request this operation.

func (*ChangeTokenTargetsMsg) Descriptor

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

func (*ChangeTokenTargetsMsg) GetMetadata

func (m *ChangeTokenTargetsMsg) GetMetadata() *weave.Metadata

func (*ChangeTokenTargetsMsg) GetNewTargets

func (m *ChangeTokenTargetsMsg) GetNewTargets() []BlockchainAddress

func (*ChangeTokenTargetsMsg) GetUsername

func (m *ChangeTokenTargetsMsg) GetUsername() Username

func (*ChangeTokenTargetsMsg) Marshal

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

func (*ChangeTokenTargetsMsg) MarshalTo

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

func (ChangeTokenTargetsMsg) Path

func (*ChangeTokenTargetsMsg) ProtoMessage

func (*ChangeTokenTargetsMsg) ProtoMessage()

func (*ChangeTokenTargetsMsg) Reset

func (m *ChangeTokenTargetsMsg) Reset()

func (*ChangeTokenTargetsMsg) Size

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

func (*ChangeTokenTargetsMsg) String

func (m *ChangeTokenTargetsMsg) String() string

func (*ChangeTokenTargetsMsg) Unmarshal

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

func (*ChangeTokenTargetsMsg) Validate

func (m *ChangeTokenTargetsMsg) Validate() error

func (*ChangeTokenTargetsMsg) XXX_DiscardUnknown

func (m *ChangeTokenTargetsMsg) XXX_DiscardUnknown()

func (*ChangeTokenTargetsMsg) XXX_Marshal

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

func (*ChangeTokenTargetsMsg) XXX_Merge

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

func (*ChangeTokenTargetsMsg) XXX_Size

func (m *ChangeTokenTargetsMsg) XXX_Size() int

func (*ChangeTokenTargetsMsg) XXX_Unmarshal

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

type Initializer added in v0.18.0

type Initializer struct{}

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

func (*Initializer) FromGenesis added in v0.18.0

func (*Initializer) FromGenesis(opts weave.Options, params weave.GenesisParams, kv weave.KVStore) error

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

type RegisterTokenMsg

type RegisterTokenMsg struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Username is the unique name of the token, for example alice*iov
	Username Username `protobuf:"bytes,2,opt,name=username,proto3,casttype=Username" json:"username,omitempty"`
	// Targets is a blockchain address list that this token should point to.
	Targets []BlockchainAddress `protobuf:"bytes,3,rep,name=targets,proto3" json:"targets"`
}

RegisterTokenMsg is creating a new username token. The owner is always set to the main signer.

func (*RegisterTokenMsg) Descriptor

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

func (*RegisterTokenMsg) GetMetadata

func (m *RegisterTokenMsg) GetMetadata() *weave.Metadata

func (*RegisterTokenMsg) GetTargets

func (m *RegisterTokenMsg) GetTargets() []BlockchainAddress

func (*RegisterTokenMsg) GetUsername

func (m *RegisterTokenMsg) GetUsername() Username

func (*RegisterTokenMsg) Marshal

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

func (*RegisterTokenMsg) MarshalTo

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

func (RegisterTokenMsg) Path

func (RegisterTokenMsg) Path() string

func (*RegisterTokenMsg) ProtoMessage

func (*RegisterTokenMsg) ProtoMessage()

func (*RegisterTokenMsg) Reset

func (m *RegisterTokenMsg) Reset()

func (*RegisterTokenMsg) Size

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

func (*RegisterTokenMsg) String

func (m *RegisterTokenMsg) String() string

func (*RegisterTokenMsg) Unmarshal

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

func (*RegisterTokenMsg) Validate

func (m *RegisterTokenMsg) Validate() error

func (*RegisterTokenMsg) XXX_DiscardUnknown

func (m *RegisterTokenMsg) XXX_DiscardUnknown()

func (*RegisterTokenMsg) XXX_Marshal

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

func (*RegisterTokenMsg) XXX_Merge

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

func (*RegisterTokenMsg) XXX_Size

func (m *RegisterTokenMsg) XXX_Size() int

func (*RegisterTokenMsg) XXX_Unmarshal

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

type Token

type Token struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Targets specifies where this username token points to. This must be at
	// least one blockchain address elemenet.
	Targets []BlockchainAddress `protobuf:"bytes,2,rep,name=targets,proto3" json:"targets"`
	// Owner is a weave.Address that controls this token. Only the owner can
	// modify a username token.
	Owner github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=owner,proto3,casttype=github.com/iov-one/weave.Address" json:"owner,omitempty"`
}

Token model represents a username mapping to an address together with all metadata.

Each Token model is stored using the username as the key. This guarantee that the name is unique. Username is a combination of a name and a domain. The format is <name>*<domain>

Each token points to a blockchain and an address on that blockchain. Both blockchain ID and address are an arbitrary string as we do not want to limit ourselves to certain patterns.

func (*Token) Copy

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

func (*Token) Descriptor

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

func (*Token) GetMetadata

func (m *Token) GetMetadata() *weave.Metadata

func (*Token) GetOwner

func (m *Token) GetOwner() github_com_iov_one_weave.Address

func (*Token) GetTargets

func (m *Token) GetTargets() []BlockchainAddress

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 payment channel is valid.

func (*Token) XXX_DiscardUnknown

func (m *Token) XXX_DiscardUnknown()

func (*Token) XXX_Marshal

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

func (*Token) XXX_Merge

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

func (*Token) XXX_Size

func (m *Token) XXX_Size() int

func (*Token) XXX_Unmarshal

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

type TransferTokenMsg

type TransferTokenMsg struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Username is the unique name of the token, for example alice*iov
	Username Username `protobuf:"bytes,2,opt,name=username,proto3,casttype=Username" json:"username,omitempty"`
	// Owner is a weave address that will owns this token after the change.
	NewOwner github_com_iov_one_weave.Address `` /* 127-byte string literal not displayed */
}

TransferTokenMsg is a request to transfer an ownership of a token. The mesage must be signed by the current token owner. Acceptance of the new owner is not required in order to succeed.

func (*TransferTokenMsg) Descriptor

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

func (*TransferTokenMsg) GetMetadata

func (m *TransferTokenMsg) GetMetadata() *weave.Metadata

func (*TransferTokenMsg) GetNewOwner

func (*TransferTokenMsg) GetUsername

func (m *TransferTokenMsg) GetUsername() Username

func (*TransferTokenMsg) Marshal

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

func (*TransferTokenMsg) MarshalTo

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

func (TransferTokenMsg) Path

func (TransferTokenMsg) Path() string

func (*TransferTokenMsg) ProtoMessage

func (*TransferTokenMsg) ProtoMessage()

func (*TransferTokenMsg) Reset

func (m *TransferTokenMsg) Reset()

func (*TransferTokenMsg) Size

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

func (*TransferTokenMsg) String

func (m *TransferTokenMsg) String() string

func (*TransferTokenMsg) Unmarshal

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

func (*TransferTokenMsg) Validate

func (m *TransferTokenMsg) Validate() error

func (*TransferTokenMsg) XXX_DiscardUnknown

func (m *TransferTokenMsg) XXX_DiscardUnknown()

func (*TransferTokenMsg) XXX_Marshal

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

func (*TransferTokenMsg) XXX_Merge

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

func (*TransferTokenMsg) XXX_Size

func (m *TransferTokenMsg) XXX_Size() int

func (*TransferTokenMsg) XXX_Unmarshal

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

type Username

type Username string

Username represents a name registered on certain domain. A valid username is in format <name>*<domain>. Username is case sensitive.

func ParseUsername

func ParseUsername(s string) (Username, error)

ParseUsername returns a valid username instance, extracted from given string representation.

func (Username) Bytes

func (u Username) Bytes() []byte

Bytes returns the byte representation of the username. Use this method when you need to use a username value as a database key.

func (Username) Domain

func (u Username) Domain() string

Name returns the name part. This is the value before the separator.

func (Username) Name

func (u Username) Name() string

Name returns the name part. This is the value before the separator.

func (Username) String

func (u Username) String() string

func (*Username) UnmarshalJSON

func (u *Username) UnmarshalJSON(raw []byte) error

Unmarshal JSON implementes unmarshaler interface. Ensure that the decoded username is valid.

func (Username) Validate

func (u Username) Validate() error

Jump to

Keyboard shortcuts

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