Documentation
¶
Overview ¶
Package xginx implements a simple multi-topic pub-sub library.
Topics must be strings and messages of any type can be published. A topic can have any number of subcribers and all of them receive messages published on the topic.
Index ¶
- Constants
- Variables
- func AesDecrypt(block cipher.Block, data []byte) ([]byte, error)
- func AesEncrypt(block cipher.Block, data []byte) ([]byte, error)
- func B58Decode(input string, alphabet *Alphabet) ([]byte, error)
- func B58Encode(input []byte, alphabet *Alphabet) string
- func BECH32Decode(adr string) (string, []byte, error)
- func BECH32Encode(hrp string, data []byte) string
- func BestValueBytes(id HASH256, h uint32) []byte
- func ByteSquasher(input []byte, inputWidth, outputWidth uint32) ([]byte, error)
- func Bytes5to8(input []byte) ([]byte, error)
- func Bytes8to5(input []byte) []byte
- func CalcBloomFilterSize(elements int, fprate float64) (uint32, uint32)
- func CalculateWorkRequired(ct uint32, pt uint32, pw uint32) uint32
- func CheckAccountArgs(num uint8, less uint8, arbon bool, pkl int) error
- func CheckExeLimit(v uint32) error
- func CheckProofOfWork(hash HASH256, bits uint32) bool
- func CheckProofOfWorkBits(bits uint32) bool
- func CheckScript(codes ...[]byte) error
- func CloseTestBlock(bi *BlockIndex)
- func CompressUInt(n uint64) uint64
- func CreateChecksum(hrp string, data []byte) []byte
- func DecodeSquashed(adr string) (string, []byte, error)
- func DecompressUInt(x uint64) uint64
- func DecompressY(x *big.Int, ybit uint) *big.Int
- func DefaultNewBlock(lis IListener, blk *BlockInfo) error
- func DefaultkFinished(blk *BlockInfo) error
- func EncodeAddressWithPrefix(prefix string, pkh HASH160) (string, error)
- func EncodePublicHash(pkh HASH256) (string, error)
- func EncodeSquashed(hrp string, data []byte) string
- func EndianUInt32(u32 uint32) []byte
- func EndianUInt64(u64 uint64) []byte
- func FixExeLimit(v uint32) uint32
- func GenPrivateKey() (k *big.Int, err error)
- func GetContext() context.Context
- func GetDBKey(p []byte, ids ...[]byte) []byte
- func GetExeLimit(v uint32) (int, time.Duration)
- func GetHRP(adr string) (string, error)
- func GetMinPowBits() uint32
- func HRPExpand(input string) []byte
- func Hash160(b []byte) []byte
- func Hash256(b []byte) []byte
- func HashDump(b []byte, pass ...string) (string, error)
- func HashLoad(s string, pass ...string) ([]byte, error)
- func HexDecode(s string) []byte
- func HexToBytes(s string) []byte
- func LinkGenesis(bi *BlockIndex)
- func ListenerLoopAccept(lis net.Listener, connfn func(conn net.Conn) error, errfn func(err error))
- func LogError(v ...interface{})
- func LogErrorf(f string, v ...interface{})
- func LogInfo(v ...interface{})
- func LogInfof(f string, v ...interface{})
- func LogWarn(v ...interface{})
- func LogWarnf(f string, v ...interface{})
- func MurmurHash(seed uint32, b []byte) uint32
- func NewAESCipher(key []byte) cipher.Block
- func NewRipemd160() hash.Hash
- func NewTempDir() string
- func NewTestOneBlock() error
- func NextHeight(h uint32) uint32
- func PackExeLimit(step uint32, time uint32) uint32
- func ParseExeLimit(v uint32) (uint32, uint32)
- func PolyMod(values []byte) uint32
- func Rand(min uint, max uint) uint
- func RandUInt32() uint32
- func ReadFull(r io.Reader, dp []byte) error
- func Ripemd160(b []byte) []byte
- func Run(lis IListener)
- func SECP256K1() elliptic.Curve
- func SegWitAddressDecode(adr string) (string, []byte, error)
- func SegWitAddressEncode(hrp string, data []byte) (string, error)
- func SegWitV0Encode(hrp string, data []byte) (string, error)
- func SetRandInt(v interface{})
- func Sha256(b []byte) []byte
- func SipHash(k0, k1 uint64, p []byte) uint64
- func SquashedBytesToString(input []byte) (string, error)
- func String(b []byte) string
- func StringToSquashedBytes(input string) ([]byte, error)
- func TimeDays(d int) time.Duration
- func TimeHour(d int) time.Duration
- func TimeMinute(d int) time.Duration
- func TimeSecond(d int) time.Duration
- func TrimAESKey(key []byte) ([]byte, error)
- func UR32() uint32
- func VerifyChecksum(hrp string, data []byte) bool
- func WriteFull(w io.Writer, dp []byte) error
- type Account
- func GetTestAccount(bi *BlockIndex) []*Account
- func LoadAccount(s string, pass ...string) (*Account, error)
- func LoadAccountWithFile(file string, pass ...string) (*Account, error)
- func NewAccount(num uint8, less uint8, arb bool, pkss ...PKBytes) (*Account, error)
- func NewAccountWithPks(num uint8, less uint8, arb bool, pkss []PKBytes) (*Account, error)
- func (ap Account) Check() error
- func (ap Account) Dump(ispri bool, pass ...string) (string, error)
- func (ap Account) DumpWithFile(file string, ispri bool, pass ...string) error
- func (ap Account) GetAddress() (Address, error)
- func (ap Account) GetPkh() (HASH160, error)
- func (ap Account) GetPkhID(idx int) (string, error)
- func (ap Account) GetPkhs() []HASH160
- func (ap Account) GetPks() []PKBytes
- func (ap Account) GetPrivateKey(pi int) *PrivateKey
- func (ap Account) HasPrivate() bool
- func (ap Account) IsEnableArb() bool
- func (ap *Account) Load(s string, pass ...string) error
- func (ap Account) NewLockedScript(meta []byte, exec ...[]byte) (Script, error)
- func (ap Account) NewWitnessScript(execs ...[]byte) *WitnessScript
- func (ap Account) Sign(pi int, hv []byte) (SigBytes, error)
- func (ap Account) SignAll(hv []byte) ([]SigBytes, error)
- func (ap Account) SignHash(hash []byte, pri *PrivateKey) (int, SigBytes, error)
- func (ap Account) String() string
- func (ap Account) VerifyAll(hv []byte, sigs []SigBytes) error
- type AccountInfo
- func (ka AccountInfo) Check() error
- func (ka *AccountInfo) Decode(bb []byte) error
- func (ka AccountInfo) Encode() ([]byte, error)
- func (ka AccountInfo) GetArb() uint8
- func (ka AccountInfo) ID() (Address, error)
- func (ka AccountInfo) MustAddress() Address
- func (ka AccountInfo) ToAccount(db IKeysDB) (*Account, error)
- type AccountJSON
- type AddrMap
- type AddrNode
- type Address
- type Alphabet
- type Amount
- type BIndexIter
- func (it *BIndexIter) Curr() *TBEle
- func (it *BIndexIter) First(skip ...int) bool
- func (it *BIndexIter) Height() uint32
- func (it *BIndexIter) ID() HASH256
- func (it *BIndexIter) Last(skip ...int) bool
- func (it *BIndexIter) Next() bool
- func (it *BIndexIter) Prev() bool
- func (it *BIndexIter) SeekHeight(h uint32, skip ...int) bool
- func (it *BIndexIter) SeekID(id HASH256, skip ...int) bool
- type Batch
- type BestValue
- type BitSet
- type BlkChunk
- type BlockEvent
- type BlockHeader
- func (v BlockHeader) Bytes() HeaderBytes
- func (v BlockHeader) Check() error
- func (v *BlockHeader) Decode(r IReader) error
- func (v *BlockHeader) Encode(w IWriter) error
- func (v *BlockHeader) ID() (HASH256, error)
- func (v BlockHeader) IsGenesis() bool
- func (v *BlockHeader) MustID() HASH256
- func (v *BlockHeader) ResetID() (HASH256, error)
- func (v BlockHeader) String() string
- type BlockIndex
- func (bi *BlockIndex) BestHeight() uint32
- func (bi *BlockIndex) CacheSize() int
- func (bi *BlockIndex) CalcBits(height uint32) uint32
- func (bi *BlockIndex) Close()
- func (bi *BlockIndex) First() *TBEle
- func (bi *BlockIndex) GetBestValue() BestValue
- func (bi *BlockIndex) GetBlockConfirm(id HASH256) int
- func (bi *BlockIndex) GetBlockHeader(id HASH256) (*TBEle, error)
- func (bi *BlockIndex) GetCoin(pkh HASH160, txid HASH256, idx VarUInt) (*CoinKeyValue, error)
- func (bi *BlockIndex) GetCoinWithAddress(addr Address, txid HASH256, idx VarUInt) (*CoinKeyValue, error)
- func (bi *BlockIndex) GetEle(id HASH256) (*TBEle, error)
- func (bi *BlockIndex) GetMsgBlock(id HASH256) (*MsgBlock, error)
- func (bi *BlockIndex) GetMsgGetInv(msg *MsgGetInv, c *Client)
- func (bi *BlockIndex) GetTxConfirm(id HASH256) int
- func (bi *BlockIndex) GetTxPool() *TxPool
- func (bi *BlockIndex) HasBlock(id HASH256) (uint32, bool)
- func (bi *BlockIndex) HasSync() bool
- func (bi *BlockIndex) HasTxValue(id HASH256) (bool, error)
- func (bi *BlockIndex) Height() uint32
- func (bi *BlockIndex) Last() *TBEle
- func (bi *BlockIndex) LastHeaders(limit int) Headers
- func (bi *BlockIndex) Len() int
- func (bi *BlockIndex) LinkBack(e *TBEle)
- func (bi *BlockIndex) LinkBlk(blk *BlockInfo) error
- func (bi *BlockIndex) ListCoins(addr Address) (*CoinsState, error)
- func (bi *BlockIndex) ListCoinsWithAccount(acc *Account) (*CoinsState, error)
- func (bi *BlockIndex) ListCoinsWithCB(addr Address, cb func(ckv *CoinKeyValue) bool) error
- func (bi *BlockIndex) ListCoinsWithID(pkh HASH160) (Coins, error)
- func (bi *BlockIndex) ListTxs(addr Address, limit ...int) (TxIndexs, error)
- func (bi *BlockIndex) ListTxsWithID(id HASH160, limit ...int) (TxIndexs, error)
- func (bi *BlockIndex) LoadAll(limit int, fn func(pv uint)) error
- func (bi *BlockIndex) LoadBlock(id HASH256) (*BlockInfo, error)
- func (bi *BlockIndex) LoadBlockWithH(h int) (*BlockInfo, error)
- func (bi *BlockIndex) LoadPrev() (*TBEle, error)
- func (bi *BlockIndex) LoadTX(id HASH256) (*TX, error)
- func (bi *BlockIndex) LoadTxValue(id HASH256) (*TxValue, error)
- func (bi *BlockIndex) NewBlock(ver uint32) (*BlockInfo, error)
- func (bi *BlockIndex) NewIter() *BIndexIter
- func (bi *BlockIndex) NewMsgGetBlock(id HASH256) MsgIO
- func (bi *BlockIndex) NewMsgHeaders(msg *MsgGetBlock) *MsgHeaders
- func (bi *BlockIndex) NewMsgTxMerkle(id HASH256) (*MsgTxMerkle, error)
- func (bi *BlockIndex) NewMsgVersion() *MsgVersion
- func (bi *BlockIndex) NewTrans(lis ITransListener) *Trans
- func (bi *BlockIndex) NextHeight() uint32
- func (bi *BlockIndex) ReadBlock(id HASH256) ([]byte, error)
- func (bi *BlockIndex) RemoveBestValue() error
- func (bi *BlockIndex) Time() uint32
- func (bi *BlockIndex) Unlink(hds Headers) error
- func (bi *BlockIndex) UnlinkCount(id HASH256) (uint32, error)
- func (bi *BlockIndex) UnlinkLast() error
- func (bi *BlockIndex) UnlinkTo(id HASH256) error
- func (bi *BlockIndex) WriteGenesis()
- type BlockInfo
- func (blk *BlockInfo) AddTxs(bi *BlockIndex, txs []*TX) error
- func (blk *BlockInfo) Check(bi *BlockIndex, csp bool) error
- func (blk *BlockInfo) CheckCoinbase() error
- func (blk *BlockInfo) CheckRefsTx(bi *BlockIndex, tx *TX) error
- func (blk *BlockInfo) CheckRepCostTxOut(bi *BlockIndex) error
- func (blk *BlockInfo) CheckTxs(bi *BlockIndex, csp bool) error
- func (blk *BlockInfo) CoinbaseFee() (Amount, error)
- func (blk *BlockInfo) CoinbaseReward() Amount
- func (blk *BlockInfo) CoinbaseScript(ip []byte, bs ...[]byte) (Script, error)
- func (blk *BlockInfo) Decode(r IReader) error
- func (blk *BlockInfo) EachOutScript(fn func(tx *TX, idx int, script *LockedScript))
- func (blk *BlockInfo) Encode(w IWriter) error
- func (blk *BlockInfo) EndianHeight() []byte
- func (blk BlockInfo) ExecScript(bi *BlockIndex) error
- func (blk *BlockInfo) Finish(bi *BlockIndex) error
- func (blk *BlockInfo) GetFee(bi *BlockIndex) (Amount, error)
- func (blk *BlockInfo) GetIncome(bi *BlockIndex) (Amount, error)
- func (blk *BlockInfo) GetMerkle() (HASH256, error)
- func (blk *BlockInfo) GetTx(idx int) (*TX, error)
- func (blk *BlockInfo) HasTx(id HASH256) bool
- func (blk *BlockInfo) ID() (HASH256, error)
- func (blk *BlockInfo) IsGenesis() bool
- func (blk *BlockInfo) LoadTxs(bi *BlockIndex) error
- func (blk *BlockInfo) MustID() HASH256
- func (blk *BlockInfo) ResetHasher()
- func (blk *BlockInfo) SetMerkle() error
- func (blk BlockInfo) String() string
- func (blk *BlockInfo) Verify(ele *TBEle, bi *BlockIndex) error
- func (blk *BlockInfo) Write(bi *BlockIndex) error
- func (blk *BlockInfo) WriteTxsIdx(bi *BlockIndex, bt *Batch) error
- type BloomFilter
- type Cache
- func (c *Cache) Add(k string, x interface{}, d time.Duration) error
- func (c *Cache) Decrement(k string, n int64) error
- func (c *Cache) DecrementFloat(k string, n float64) error
- func (c *Cache) DecrementFloat32(k string, n float32) (float32, error)
- func (c *Cache) DecrementFloat64(k string, n float64) (float64, error)
- func (c *Cache) DecrementInt(k string, n int) (int, error)
- func (c *Cache) DecrementInt16(k string, n int16) (int16, error)
- func (c *Cache) DecrementInt32(k string, n int32) (int32, error)
- func (c *Cache) DecrementInt64(k string, n int64) (int64, error)
- func (c *Cache) DecrementInt8(k string, n int8) (int8, error)
- func (c *Cache) DecrementUint(k string, n uint) (uint, error)
- func (c *Cache) DecrementUint16(k string, n uint16) (uint16, error)
- func (c *Cache) DecrementUint32(k string, n uint32) (uint32, error)
- func (c *Cache) DecrementUint64(k string, n uint64) (uint64, error)
- func (c *Cache) DecrementUint8(k string, n uint8) (uint8, error)
- func (c *Cache) DecrementUintptr(k string, n uintptr) (uintptr, error)
- func (c *Cache) Delete(k string)
- func (c *Cache) DeleteExpired()
- func (c *Cache) Flush()
- func (c *Cache) Get(k string) (interface{}, bool)
- func (c *Cache) GetWithExpiration(k string) (interface{}, time.Time, bool)
- func (c *Cache) Increment(k string, n int64) error
- func (c *Cache) IncrementFloat(k string, n float64) error
- func (c *Cache) IncrementFloat32(k string, n float32) (float32, error)
- func (c *Cache) IncrementFloat64(k string, n float64) (float64, error)
- func (c *Cache) IncrementInt(k string, n int) (int, error)
- func (c *Cache) IncrementInt16(k string, n int16) (int16, error)
- func (c *Cache) IncrementInt32(k string, n int32) (int32, error)
- func (c *Cache) IncrementInt64(k string, n int64) (int64, error)
- func (c *Cache) IncrementInt8(k string, n int8) (int8, error)
- func (c *Cache) IncrementUint(k string, n uint) (uint, error)
- func (c *Cache) IncrementUint16(k string, n uint16) (uint16, error)
- func (c *Cache) IncrementUint32(k string, n uint32) (uint32, error)
- func (c *Cache) IncrementUint64(k string, n uint64) (uint64, error)
- func (c *Cache) IncrementUint8(k string, n uint8) (uint8, error)
- func (c *Cache) IncrementUintptr(k string, n uintptr) (uintptr, error)
- func (c *Cache) ItemCount() int
- func (c *Cache) Items() map[string]Item
- func (c *Cache) Load(r io.Reader) error
- func (c *Cache) LoadFile(fname string) error
- func (c *Cache) OnEvicted(f func(string, interface{}))
- func (c *Cache) Replace(k string, x interface{}, d time.Duration) error
- func (c *Cache) Save(w io.Writer) (err error)
- func (c *Cache) SaveFile(fname string) error
- func (c *Cache) Set(k string, x interface{}, d time.Duration)
- func (c *Cache) SetDefault(k string, x interface{})
- type Client
- func (c *Client) Close()
- func (c *Client) Equal(b *Client) bool
- func (c *Client) FilterAdd(key []byte) error
- func (c *Client) FilterClear()
- func (c *Client) FilterHas(key []byte) bool
- func (c *Client) GetFilter() (*BloomFilter, bool)
- func (c *Client) ID() uint64
- func (c *Client) IsIn() bool
- func (c *Client) IsOut() bool
- func (c *Client) LoadFilter(funcs uint32, tweak uint32, filter []byte) error
- func (c *Client) Loop()
- func (c *Client) Open(addr NetAddr) error
- func (c *Client) SendMsg(m MsgIO)
- type ClientMsg
- type CoinKeyValue
- func (tk *CoinKeyValue) From(k []byte, v []byte) error
- func (tk CoinKeyValue) GetAddress() Address
- func (tk CoinKeyValue) ID() string
- func (tk CoinKeyValue) IsMatured(spent uint32) bool
- func (tk CoinKeyValue) IsPool() bool
- func (tk CoinKeyValue) MustKey() []byte
- func (tk CoinKeyValue) MustValue() []byte
- func (tk CoinKeyValue) NewTxIn(wits *WitnessScript) (*TxIn, error)
- func (tk CoinKeyValue) SpentKey() []byte
- type Coins
- type CoinsState
- type Config
- type CtrlPrivateKeyReq
- type CtrlPrivateKeyRes
- type DBImp
- type Document
- type DocumentID
- func (id *DocumentID) Decode(r IReader) error
- func (id DocumentID) Encode(w IWriter) error
- func (id DocumentID) Equal(v DocumentID) bool
- func (id DocumentID) IsNil() bool
- func (id DocumentID) MarshalJSON() ([]byte, error)
- func (id *DocumentID) SetType(typ byte)
- func (id DocumentID) String() string
- func (id DocumentID) To(typ byte) DocumentID
- func (id DocumentID) Type() byte
- func (id *DocumentID) UnmarshalJSON(b []byte) error
- type FLocker
- type HASH160
- func DecodeAddress(addr Address) (HASH160, error)
- func DecodeAddressWithPrefix(addr string) (string, HASH160, error)
- func Hash160From(b []byte) HASH160
- func HashPkh(num uint8, less uint8, arb uint8, pkhs []HASH256) (HASH160, error)
- func HashPks(num uint8, less uint8, arb uint8, pks []PKBytes) (HASH160, error)
- func NewHASH160(v interface{}) HASH160
- type HASH256
- func (h HASH256) Bytes() []byte
- func (h HASH256) Clone() HASH256
- func (h *HASH256) Decode(r IReader) error
- func (h HASH256) Encode(w IWriter) error
- func (h HASH256) Equal(v HASH256) bool
- func (h HASH256) EqualBytes(b []byte) bool
- func (h HASH256) GetUint64(idx int) uint64
- func (h HASH256) IsZero() bool
- func (h *HASH256) Set(b []byte)
- func (h HASH256) String() string
- func (h HASH256) Swap() HASH256
- func (h HASH256) ToU256() UINT256
- type HashCacher
- type HeaderBytes
- type Headers
- type IBlkStore
- type IChunkStore
- type ICoder
- type IDocIter
- type IDocSystem
- type IGetSigBytes
- type IKeysDB
- type IListener
- type IMiner
- type IMsgMeta
- type INetStream
- type IReadWriter
- type IReader
- type ISerializable
- type IServer
- type ISignTx
- type ISigner
- type ITransListener
- type IWriter
- type Inventory
- type Item
- type Iterator
- type LockedScript
- type MerkleTree
- func (tree *MerkleTree) Bits() *BitSet
- func (tree *MerkleTree) Build(ids []HASH256, vb *BitSet) *MerkleTree
- func (tree *MerkleTree) CalcHash(height int, pos int, ids []HASH256) HASH256
- func (tree *MerkleTree) Extract() (HASH256, []HASH256, []int)
- func (tree *MerkleTree) ExtractRoot() (HASH256, error)
- func (tree *MerkleTree) Hash(n1 HASH256, n2 HASH256) HASH256
- func (tree *MerkleTree) Hashs() []HASH256
- func (tree *MerkleTree) Height() int
- func (tree MerkleTree) IsBad() bool
- func (tree *MerkleTree) Trans() int
- func (tree *MerkleTree) TreeWidth(height int) int
- type MinerAct
- type MinerGroup
- type MsgAddrs
- type MsgAlert
- type MsgBlock
- type MsgBroadAck
- type MsgBroadPkg
- type MsgError
- type MsgFilterAdd
- type MsgFilterClear
- type MsgFilterLoad
- type MsgGetAddrs
- type MsgGetBlock
- type MsgGetInv
- type MsgGetMerkle
- type MsgGetTxPool
- type MsgHeaders
- type MsgID
- type MsgIO
- type MsgInv
- type MsgPing
- type MsgPong
- type MsgTx
- type MsgTxMerkle
- type MsgTxPool
- type MsgVersion
- type NTType
- type NetAddr
- func (c NetAddr) Addr(h ...string) string
- func (c *NetAddr) Decode(r IReader) error
- func (c NetAddr) Encode(w IWriter) error
- func (c NetAddr) Equal(d NetAddr) bool
- func (c *NetAddr) From(s string) error
- func (c NetAddr) IP() []byte
- func (c NetAddr) IsGlobalUnicast() bool
- func (c NetAddr) Network() string
- func (c NetAddr) String() string
- func (c NetAddr) ToTCPAddr() *net.TCPAddr
- type NetPackage
- type NetStream
- func (s *NetStream) Bytes() []byte
- func (s *NetStream) Len() int
- func (s *NetStream) ReadByte() (byte, error)
- func (s *NetStream) ReadFull(dp []byte) error
- func (s *NetStream) ReadMsg(attr ...*uint8) (MsgIO, error)
- func (s *NetStream) Reset()
- func (s *NetStream) TRead(data interface{}) error
- func (s *NetStream) TWrite(data interface{}) error
- func (s *NetStream) WriteByte(b byte) error
- func (s *NetStream) WriteFull(dp []byte) error
- func (s *NetStream) WriteMsg(m MsgIO, attrs ...uint8) error
- type ONCE
- type PKBytes
- func (v PKBytes) Bytes() []byte
- func (v PKBytes) Cmp(b PKBytes) int
- func (v *PKBytes) Decode(r IReader) error
- func (v PKBytes) Encode(w IWriter) error
- func (v PKBytes) Equal(b PKBytes) bool
- func (v PKBytes) Hash() HASH160
- func (v PKBytes) Hash256() HASH256
- func (v PKBytes) IsValid() bool
- func (v *PKBytes) Set(pk *PublicKey) PKBytes
- func (v *PKBytes) SetBytes(b []byte)
- type PrivateKey
- func (pk *PrivateKey) Bytes() []byte
- func (pk *PrivateKey) Clone() *PrivateKey
- func (pk *PrivateKey) Decode(data []byte) error
- func (pk *PrivateKey) Dump(pass ...string) (string, error)
- func (pk *PrivateKey) Encode() []byte
- func (pk *PrivateKey) IsValid() bool
- func (pk *PrivateKey) Load(s string, pass ...string) error
- func (pk PrivateKey) Marshal() []byte
- func (pk PrivateKey) New(plus []byte) *PrivateKey
- func (pk *PrivateKey) PublicKey() *PublicKey
- func (pk *PrivateKey) SetBytes(b []byte) *PrivateKey
- func (pk PrivateKey) Sign(hash []byte) (*SigValue, error)
- func (pk PrivateKey) String() string
- type PrivatesMap
- type PubSub
- func (ps *PubSub) AddSub(ch chan interface{}, topics ...string)
- func (ps *PubSub) AddSubOnceEach(ch chan interface{}, topics ...string)
- func (ps *PubSub) Close(topics ...string)
- func (ps *PubSub) Pub(msg interface{}, topics ...string)
- func (ps *PubSub) Shutdown()
- func (ps *PubSub) Sub(topics ...string) chan interface{}
- func (ps *PubSub) SubOnce(topics ...string) chan interface{}
- func (ps *PubSub) SubOnceEach(topics ...string) chan interface{}
- func (ps *PubSub) TryPub(msg interface{}, topics ...string)
- func (ps *PubSub) Unsub(ch chan interface{}, topics ...string)
- type PublicArray
- type PublicKey
- func (pk *PublicKey) Decode(data []byte) error
- func (pk *PublicKey) Dump(pass ...string) (string, error)
- func (pk *PublicKey) Encode() []byte
- func (pk *PublicKey) Equal(sb []byte) bool
- func (pk *PublicKey) FromHEX(s string) error
- func (pk *PublicKey) GetPks() PKBytes
- func (pk *PublicKey) Hash() HASH160
- func (pk *PublicKey) ID() (string, error)
- func (pk *PublicKey) IsValid() bool
- func (pk *PublicKey) Load(s string, pass ...string) (*PublicKey, error)
- func (pk *PublicKey) Verify(hash []byte, sig *SigValue) bool
- type RSAPrivateKey
- func (ptr RSAPrivateKey) Decrypt(bb []byte) ([]byte, error)
- func (ptr RSAPrivateKey) Dump(pass ...string) (string, error)
- func (ptr RSAPrivateKey) ID() (string, error)
- func (ptr *RSAPrivateKey) Load(str string, pass ...string) error
- func (ptr RSAPrivateKey) PublicKey() *RSAPublicKey
- func (ptr RSAPrivateKey) Sign(src []byte) ([]byte, error)
- type RSAPublicKey
- func (ptr RSAPublicKey) Dump() (string, error)
- func (ptr RSAPublicKey) Encrypt(bb []byte) ([]byte, error)
- func (ptr RSAPublicKey) ID() (string, error)
- func (ptr *RSAPublicKey) Load(str string) error
- func (ptr RSAPublicKey) MustID() string
- func (ptr RSAPublicKey) Verify(src []byte, sign []byte) error
- type Range
- type Script
- func (s Script) Check() error
- func (s Script) Clone() Script
- func (s Script) Data() []byte
- func (s *Script) Decode(r IReader) error
- func (s Script) Encode(w IWriter) error
- func (s Script) ForID(w IWriter) error
- func (s Script) ForVerify(w IWriter) error
- func (s Script) GetAddress() (Address, error)
- func (s Script) GetPkh() (HASH160, error)
- func (s Script) GetType() uint8
- func (s Script) Height() uint32
- func (s Script) IP() []byte
- func (s Script) IsCoinBase() bool
- func (s Script) IsLocked() bool
- func (s Script) IsTxScript() bool
- func (s Script) IsWitness() bool
- func (s Script) Len() int
- func (s Script) MustPkh() HASH160
- func (s Script) To() (interface{}, error)
- func (s Script) ToLocked() (*LockedScript, error)
- func (s Script) ToTxScript() (*TxScript, error)
- func (s Script) ToWitness() (*WitnessScript, error)
- func (s Script) Type() uint8
- type SigBytes
- type SigValue
- type TBEle
- type TBMeta
- type TCPServer
- func (s *TCPServer) Addrs() []*AddrNode
- func (s *TCPServer) BroadMsg(m MsgIO, skips ...*Client) int
- func (s *TCPServer) Broadcast(m MsgIO, skips ...*Client) int
- func (s *TCPServer) Clients() []*Client
- func (s *TCPServer) ConnNum() int
- func (s *TCPServer) DelClient(id uint64, c *Client)
- func (s *TCPServer) DoOpt(opt int)
- func (s *TCPServer) GetPkg(id string) (MsgIO, bool)
- func (s *TCPServer) HasClient(id uint64, c *Client) bool
- func (s *TCPServer) HasPkg(id string) bool
- func (s *TCPServer) IsAddrOpen(addr NetAddr) bool
- func (s *TCPServer) IsOpen(id uint64) bool
- func (s *TCPServer) NewClient() *Client
- func (s *TCPServer) NewClientWithConn(conn net.Conn) *Client
- func (s *TCPServer) NewMsgAddrs(c *Client) *MsgAddrs
- func (s *TCPServer) Run()
- func (s *TCPServer) SetPkg(id string, m MsgIO)
- func (s *TCPServer) Start(ctx context.Context, lptr IListener)
- func (s *TCPServer) Stop()
- func (s *TCPServer) Wait()
- type TRImp
- type TX
- func (tx *TX) Check(bi *BlockIndex, csp bool) error
- func (tx TX) Clone(seq ...uint) *TX
- func (tx *TX) CoinbaseFee() (Amount, error)
- func (tx *TX) CoinsIsValid(bi *BlockIndex) bool
- func (tx *TX) Decode(r IReader) error
- func (tx *TX) Encode(w IWriter) error
- func (tx *TX) ExecScript(bi *BlockIndex) error
- func (tx *TX) GetFeeAmount(bi *BlockIndex) (Amount, error)
- func (tx *TX) HasRepTxIn(bi *BlockIndex, csp bool) bool
- func (tx *TX) ID() (HASH256, error)
- func (tx *TX) IsCoinBase() bool
- func (tx TX) IsFinal() bool
- func (tx TX) IsPool() bool
- func (tx TX) IsReplace(old *TX) bool
- func (tx *TX) MustID() HASH256
- func (tx *TX) ResetAll()
- func (tx *TX) ResetSign()
- func (tx *TX) Sign(bi *BlockIndex, lis ISignTx, pass ...string) error
- func (tx TX) String() string
- func (tx *TX) Verify(bi *BlockIndex) error
- type TestLis
- func (lis *TestLis) GetAccount(i int) *Account
- func (lis *TestLis) MinerAddr() Address
- func (lis *TestLis) OnClientMsg(c *Client, msg MsgIO)
- func (lis *TestLis) OnClose()
- func (lis *TestLis) OnFinished(blk *BlockInfo) error
- func (lis *TestLis) OnInit(bi *BlockIndex) error
- func (lis *TestLis) OnLinkBlock(blk *BlockInfo)
- func (lis *TestLis) OnLoadTxs(txs []*TX) []*TX
- func (lis *TestLis) OnNewBlock(blk *BlockInfo) error
- func (lis *TestLis) OnSignTx(signer ISigner) error
- func (lis *TestLis) OnStart()
- func (lis *TestLis) OnStop()
- func (lis *TestLis) OnTxPool(tx *TX) error
- func (lis *TestLis) OnTxPoolRep(old *TX, new *TX)
- func (lis *TestLis) OnUnlinkBlock(blk *BlockInfo)
- func (lis *TestLis) TimeNow() uint32
- type Trans
- type TxEvent
- type TxIn
- func (in *TxIn) Check(bi *BlockIndex) error
- func (in TxIn) Clone(seq ...uint) *TxIn
- func (in *TxIn) Decode(r IReader) error
- func (in *TxIn) Encode(w IWriter) error
- func (in *TxIn) ForID(w IWriter) error
- func (in TxIn) GetCoin(bi *BlockIndex) (*CoinKeyValue, error)
- func (in *TxIn) IsCoinBase() bool
- func (in *TxIn) LoadTxOut(bi *BlockIndex) (*TxOut, error)
- func (in TxIn) OutKey() HASH256
- func (in TxIn) SpentKey() []byte
- type TxIndex
- type TxIndexs
- type TxOut
- func (out *TxOut) Check(bi *BlockIndex) error
- func (out TxOut) Clone() *TxOut
- func (out *TxOut) Decode(r IReader) error
- func (out *TxOut) Encode(w IWriter) error
- func (out *TxOut) ForID(w IWriter) error
- func (out *TxOut) GetCoin(in *TxIn, bi *BlockIndex) (*CoinKeyValue, error)
- func (out *TxOut) HasCoin(in *TxIn, bi *BlockIndex) bool
- func (out TxOut) IsPool() bool
- type TxPool
- func (pool *TxPool) AllTxs() []*TX
- func (pool *TxPool) Close()
- func (pool *TxPool) Del(bi *BlockIndex, id HASH256)
- func (pool *TxPool) DelTxs(bi *BlockIndex, txs []*TX)
- func (pool *TxPool) Dump(file string) error
- func (pool *TxPool) Get(id HASH256) (*TX, error)
- func (pool *TxPool) GetCoin(pkh HASH160, txid HASH256, idx VarUInt) (*CoinKeyValue, error)
- func (pool *TxPool) GetDelTxs(bi *BlockIndex, txs []*TX) []*TX
- func (pool *TxPool) Has(id HASH256) bool
- func (pool *TxPool) HasCoin(coin *CoinKeyValue) bool
- func (pool *TxPool) IsSpent(skey []byte) bool
- func (pool *TxPool) IsSpentCoin(coin *CoinKeyValue) bool
- func (pool *TxPool) Len() int
- func (pool *TxPool) ListCoins(spkh HASH160) (Coins, error)
- func (pool *TxPool) ListTxsWithID(bi *BlockIndex, spkh HASH160, limit ...int) (TxIndexs, error)
- func (pool *TxPool) Load(bi *BlockIndex, file string) error
- func (pool *TxPool) LoadTxsWithBlk(bi *BlockIndex, blk *BlockInfo) ([]*TX, error)
- func (pool *TxPool) NewMsgGetTxPool() *MsgGetTxPool
- func (pool *TxPool) NewMsgTxPool(m *MsgGetTxPool) *MsgTxPool
- func (pool *TxPool) PushTx(bi *BlockIndex, tx *TX) error
- func (pool *TxPool) PushTxs(bi *BlockIndex, msg *MsgTxPool)
- type TxScript
- type TxValue
- type UINT256
- func (h UINT256) Add(b UINT256) UINT256
- func (h UINT256) Bits() uint
- func (h UINT256) Cmp(b UINT256) int
- func (h UINT256) Compact(negative bool) uint32
- func (h UINT256) Div(b UINT256) UINT256
- func (h UINT256) Equal(v UINT256) bool
- func (h UINT256) IsZero() bool
- func (h UINT256) Low64() uint64
- func (h UINT256) Lshift(shift uint) UINT256
- func (h UINT256) Mul(v UINT256) UINT256
- func (h UINT256) MulUInt32(v uint32) UINT256
- func (h UINT256) Neg() UINT256
- func (h UINT256) Rshift(shift uint) UINT256
- func (h *UINT256) SetCompact(c uint32) (bool, bool)
- func (h *UINT256) SetValue(v interface{})
- func (h UINT256) String() string
- func (h UINT256) Sub(b UINT256) UINT256
- func (h UINT256) ToDouble() float64
- func (h UINT256) ToHASH256() HASH256
- type VarBytes
- type VarInt
- type VarUInt
- func (v VarUInt) Bytes() []byte
- func (v *VarUInt) Decode(r IReader) error
- func (v VarUInt) Encode(w IWriter) error
- func (v *VarUInt) From(b []byte) int
- func (v *VarUInt) SetInt(uv int)
- func (v *VarUInt) SetUInt32(uv uint32)
- func (v VarUInt) SortBytes() []byte
- func (v VarUInt) ToAmount() Amount
- func (v VarUInt) ToInt() int
- func (v VarUInt) ToUInt32() uint32
- type WitnessScript
- func (ss WitnessScript) Address() Address
- func (ss WitnessScript) Check() error
- func (ss WitnessScript) CheckSigs(sigs []SigBytes) error
- func (ss *WitnessScript) Decode(r IReader) error
- func (ss WitnessScript) Encode(w IWriter) error
- func (ss *WitnessScript) Final() (Script, error)
- func (ss WitnessScript) ForID(w IWriter) error
- func (ss WitnessScript) Hash() (HASH160, error)
- func (ss WitnessScript) IsEnableArb() bool
- func (ss WitnessScript) ToAccount() (*Account, error)
- func (ss WitnessScript) ToScript() (Script, error)
Constants ¶
const ( //MaxCompressUInt 压缩金额可存储的最大数字 MaxCompressUInt = uint64(0b1111 << 57) //Coin 分割系数 1Coin 可分割1000份 Coin = Amount(1000) // MaxMoney < MaxCompressUInt MaxMoney = 21000000 * Coin )
金额定义
const ( //最大块大小 MaxBlockSize = 1024 * 1024 * 8 //最大日志大小 MaxLogSize = 1024 * 1024 * 4 //最大执行脚本长度 MaxExecSize = 1024 * 2 //最大meta数据长度 MaxMetaSize = 1024 * 4 //默认: 50步,1=30毫秒 DefaultExeLimit = (30 << 16) | 30000 //高16位限制执行步数,低16位限制执行时间,单位:微秒 MaxExeTimeLimit = uint32(0xFFFF) //65毫秒 MaxExeStepLimit = uint32(30000) //6万step //coinbase需要100区块后可用 CoinbaseMaturity = 100 //如果所有的输入全是 >= FinalSequence,交易立即生效 FinalSequence = VarUInt(0xFFFFFF) )
常量定义
const ( //如果是新出的区块设置此标记并广播 MsgBlockNewFlags = 1 << 0 //使用Bytes原始字节打包传输 MsgBlockUseBytes = 1 << 1 //使用Blk对象打包传输 MsgBlockUseBlk = 1 << 2 )
区块消息标记
const ( MaxBloomFilterSize = 36000 MaxHashFuncs = 50 Ln2Squared = 0.4804530139182014246671025263266649717305529515945455 )
布隆过滤器定义
const ( //NoExpiration For use with functions that take an expiration time. NoExpiration time.Duration = -1 //DefaultExpiration For use with functions that take an expiration time. Equivalent to // passing in the same expiration duration as was given to New() or // NewFrom() when the cache was created (e.g. 5 minutes.) DefaultExpiration time.Duration = 0 )
const ( ClientIn = 1 ClientOut = 2 )
连接类型
const ( //交易脚本 ExecTypeTxMain = "TxMain" //输\入脚本 ExecTypeInMain = "InMain" //输出脚本 ExecTypeOutMain = "OutMain" )
脚本类型
const ( //金额账户 CoinAccountType = 1 //临时账户 TempAccountType = 2 )
const ( //矿工操作 MinerAct NewMinerActTopic = "NewMinerAct" //更新了一个区块数据 BlockInfo NewLinkBlockTopic = "NewLinkBlock" //接收的广播区块 NewRecvBlockTopic = "NewRecvBlock" //当交易池中的交易被移除时 txid TxPoolDelTxTopic = "TxPoolDelTx" //每隔多少秒打印挖掘状态 MinerLogSeconds = 5 )
订阅消息类型
const ( //开始挖矿操作 args(uint32) = block ver OptGenBlock = iota //停止当前区块创建 OptStopGenBlock //发送一个区块头数据进行验证 args = HeaderBytes OptSendHeadBytes )
操作定义
const ( NtVersion = NTType(1) //ping/pong NtPing = NTType(2) NtPong = NTType(3) //获取节点连接的其他地址 NtGetAddrs = NTType(4) NtAddrs = NTType(5) //inv 交易或者区块通报 //当有新的交易或者区块生成通报给周边的节点 NtInv = NTType(6) //获取交易或者区块 NtGetInv = NTType(7) //获取交易的返回 NtTx = NTType(8) //获取区块的返回 NtBlock = NTType(9) //获取区块按高度 NtGetBlock = NTType(10) //返回区块头列表 NtHeaders = NTType(11) //返回一个错误信息 NtError = NTType(12) //消息通知 NtAlert = NTType(13) //过滤器 加载 添加 清除 NtFilterLoad = NTType(14) NtFilterAdd = NTType(15) NtFilterClear = NTType(16) //交易merkle树 NtGetMerkle = NTType(17) NtTxMerkle = NTType(18) //获取内存交易池 NtGetTxPool = NTType(19) NtTxPool = NTType(20) //广播包头和响应,当广播消息时只发送广播包头,收到包头如果确定无需要收取数据再请求包数据 NtBroadPkg = NTType(0xf0) NtBroadAck = NTType(0xf1) )
协议包标识
const ( ErrCodeRecvBlock = 100001 ErrCodeRecvTx = 100002 ErrCodeFilterMiss = 100003 ErrCodeFilterLoad = 100004 ErrCodeTxMerkle = 100005 ErrCodeBlockMiss = 100006 ErrCodeHeaders = 100007 )
消息错误代码
const ( InvalidArb = ^uint8(0) //无效的仲裁 ScriptCoinbaseType = uint8(0) //coinbase script ScriptLockedType = uint8(1) //标准锁定脚本 用于输出 ScriptWitnessType = uint8(2) //隔离见证多重签名脚本 用于输入 ScriptTxType = uint8(3) //交易脚本 用于控制交易是否打包进区块,是否进入交易池,是否发布上网 MaxCoinbaseScriptSize = 256 //最大coinbase脚本长度 )
脚本类型定义 Script 第一个字节表示脚本类型
const ( //收到所有消息 NetMsgTopic = "NetMsg" //创建了新的交易进入了交易池 NewTxTopic = "NewTx" //默认端口 DefaultPort = uint16(9333) )
消息订阅
const ( //公钥长度 PublicKeySize = 33 //偶数公钥前缀 P256PubKeyEven = byte(0x02) //奇数公钥前缀 P256PubKeyOdd = byte(0x03) //公钥ID前缀 PublicIDPrefix = "pk" //地址前缀 AddressPrefix = "st" )
公钥定义
const ( //交易类型 InvTypeTx = uint8(1) //块类型 InvTypeBlock = uint8(2) )
inv类型定义
const ( //MaxTxPoolSize 交易池最大数量 MaxTxPoolSize = 4096 * 4 //TxPoolFile 交易池数据保存文件 TxPoolFile = "txpool.dat" )
交易池最大数量
const (
AccountKeyMaxSize = 16
)
账号最大的私钥数量
const (
//全节点
FullNodeFlag = 1 << 0
)
节点类型定义
const ( // 无效的块高度 InvalidHeight = ^uint32(0) )
定义高度
const (
MapKeyFilter = "BloomFilter"
)
属性名称
const ( //PackageAttrZip 数据是否启用压缩 PackageAttrZip = uint8(1 << 0) )
数据包属性
const (
//RSABits 默认rsa加密强度
RSABits = 2048
)
const Ripemd160BlockSize = 64
Ripemd160BlockSize The block size of the hash algorithm in bytes.
const Ripemd160Size = 20
Ripemd160Size The size of the checksum in bytes.
const (
UInt256Width = 256 / 32
)
hash宽度
Variables ¶
var ( BitcoinAlphabet = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") IPFSAlphabet = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") FlickrAlphabet = NewAlphabet("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ") RippleAlphabet = NewAlphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") )
Alphabet: copy from https://en.wikipedia.org/wiki/Base58
var ( BestBlockKey = []byte("BestBlockKey") //最高区块数据保存key InvalidBest = NewInvalidBest() //无效的状态 )
区块定义
var ( //ErrArriveFirstBlock 到达第一个 ErrArriveFirstBlock = errors.New("arrive first block") //ErrEmptyBlockChain 空链 ErrEmptyBlockChain = errors.New("this is empty chain") //ErrHeadersScope 当获取到的区块头在链中无法找到时 ErrHeadersScope = errors.New("all hds not in scope") //ErrHeadersTooLow 证据区块头太少 ErrHeadersTooLow = errors.New("headers too low") )
错误定义
var ( ConfFile = flag.String("conf", "v10000.json", "config file name") IsDebug = flag.Bool("debug", true, "startup mode") )
启动参数
var ( //DefaultTxScript 默认交易脚本 控制是否能进入区块 DefaultTxScript = []byte(`return true`) //DefaultInputScript 默认输入脚本 控制是否能消费 DefaultInputScript = []byte(`return true`) //DefaultLockedScript 默认锁定脚本 控制消费输出需要的条件 //验证地址和签名 DefaultLockedScript = []byte(`return verify_addr() and verify_sign()`) )
var ( ErrDataSize = errors.New("size data error") Endian = binary.LittleEndian ErrVarSize = errors.New("var size too big") ZERO256 = HASH256{} ZERO160 = HASH160{} )
hash定义
var ( ErrNotID = errors.New("msg not id,can't broad") ErrMsgID = MsgID{} )
错误定义
var ( PrefixSecretKey = []byte{128} PKBytesZero = PKBytes{} SigBytesZero = SigBytes{} )
算法
var ( BlockPrefix = []byte{1} //块头信息前缀 ->blkmeta TxsPrefix = []byte{2} //tx 所在区块前缀 ->blkid+txidx CoinsPrefix = []byte{3} //账户可用金额存储 pkh_txid_idx -> amount TxpPrefix = []byte{4} //账户相关交易索引 按高度排序 pkh_height(big endian)_txid -> blkid+txidx )
数据前缀定义
var ( //AutoGenBlockTime 自动创建区块时间 AutoGenBlockTime = time.Second * 30 )
var ( //CoinSplit 1个coin可分割为1000份 CoinSplit = decimal.NewFromInt(int64(Coin)) )
var DocumentIDLen = len(NilDocumentID)
var ( //ErrCheckSum 校验和错误,一般密码错误会出现这个问题 ErrCheckSum = errors.New("check sum error, maybe password error") )
var ( //需要切换到下一个文件存储 ErrNextFile = errors.New("next file") )
错误
var (
ErrorInvalidBase58String = errors.New("invalid base58 string")
)
Errors
var (
Miner = newMinerEngine()
)
默认矿工处理
var (
Separator = string(os.PathSeparator)
)
系统路径分隔符
var (
Server = NewTCPServer()
)
默认服务
Functions ¶
func BECH32Decode ¶
BECH32Decode takes a bech32 encoded string and returns the hrp and the full-height data. Can error out for various reasons, mostly problems in the string given. Doesn't do anything segwit specific.
func BECH32Encode ¶
BECH32Encode takes regular bytes of data, and an hrp prefix, and returns the bech32 encoded string. It doesn't do any segwit specific encoding.
func ByteSquasher ¶
ByteSquasher squashes full-width (8-bit) bytes into "squashed" 5-bit bytes, and vice versa. It can operate on other widths but in this package only goes 5 to 8 and back again. It can return an error if the squashed input you give it isn't actually squashed, or if there is padding (trailing q characters) when going from 5 to 8
func Bytes8to5 ¶
Bytes8to5 extends a byte slice into a longer, padded byte slice of 5-bit elements where the high 3 bits are all 0.
func CalcBloomFilterSize ¶
CalcBloomFilterSize 结算需要的存储量和hash次数
func CalculateWorkRequired ¶
CalculateWorkRequired 计算工作难度 ct = lastBlock blockTime pt = lastBlock - 2016 + 1 blockTime pw = lastBlock's bits
func CheckAccountArgs ¶
CheckAccountArgs 检测账户参数
func CheckProofOfWork ¶
CheckProofOfWork whether a block hash satisfies the proof-of-work requirement specified by nBits
func CheckProofOfWorkBits ¶
CheckProofOfWorkBits 检测难度值是否正确
func CreateChecksum ¶
CreateChecksum makes a 6-shortbyte checksum from the HRP and data parts
func DecodeSquashed ¶
DecodeSquashed is the same as Decode, but will return squashed 5-bit high data.
func DecompressY ¶
DecompressY 为压缩公钥计算y y^2 = x^3 + b y = sqrt(x^3 + b)
func DefaultNewBlock ¶
OnNewBlock 当块创建完毕 默认创建coinbase交易加入区块为区块第一个交易
func EncodeAddressWithPrefix ¶
EncodeAddressWithPrefix 编码地址用指定前缀
func EncodePublicHash ¶
EncodePublicHash 编码公钥hash
func EncodeSquashed ¶
EncodeSquashed takes the hrp prefix, as well as byte data that has already been squashed to 5-bits high, and returns the bech32 encoded string. It does not return an error; if you give it non-squashed data it will return an empty string.
func GetHRP ¶
GetHRP Segwit addresses can't be used in Encode and Decode directly, because the witness version is special and doesn't get squashed. GetHRP gets the HRP without checking any validity.
func ListenerLoopAccept ¶
开始监听链接
func NewRipemd160 ¶
NewRipemd160 returns a new hash.Hash computing the checksum.
func PolyMod ¶
PolyMod takes a byte slice and returns the 32-bit BCH checksum. Note that the input bytes to PolyMod need to be squashed to 5-bits tall before being used in this function. And this function will not error, but instead return an unsuable checksum, if you give it full-height bytes.
func SegWitAddressDecode ¶
SegWitAddressDecode takes a segwit address and returns the pkscript that can go directly into the txout. (includes version byte and data push byte)
func SegWitAddressEncode ¶
SegWitAddressEncode takes an hrp and data and gives back a segwit address. The data that goes in should be the full pkscript from the txout, including the version byte and the pushdata byte.
func SegWitV0Encode ¶
SegWitV0Encode takes an hrp prefix string and a 20 or 32 byte witness program hash, and turns it into a version 0 address. (it puts the 0 and pushdata in for you.
func SquashedBytesToString ¶
SquashedBytesToString swaps 5-bit bytes with a string of the corresponding letters
func StringToSquashedBytes ¶
StringToSquashedBytes uses the inverseCharset to switch from the characters back to 5-bit squashed bytes.
func VerifyChecksum ¶
VerifyChecksum verify checksum
Types ¶
type Account ¶
type Account struct { Num uint8 //总的密钥数量 Less uint8 //至少需要签名的数量 Arb uint8 //仲裁,当less < num时可启用,必须是最后一个公钥 Pubs PublicArray //所有的密钥公钥 Pris PrivatesMap //公钥对应的私钥,按公钥pkh锁应保存 }
Account 账号地址 可以包含多个签名,但正确签名数量至少是less指定的数量 如果启用了仲裁功能,只需要仲裁签名正确也可以通过签名
func LoadAccount ¶
LoadAccount 从导出的数据加载账号
func LoadAccountWithFile ¶
LoadAccountWithFile 从文件加载证书
func NewAccount ¶
NewAccount 创建num个证书的账号,至少需要less个签名 arb是否启用仲裁 有pkss将不包含私钥
func NewAccountWithPks ¶
NewAccountWithPks 创建无私钥账号 不能用来签名
func (Account) DumpWithFile ¶
DumpWithFile 导出到文件
func (Account) GetPrivateKey ¶
func (ap Account) GetPrivateKey(pi int) *PrivateKey
GetPrivateKey 根据公钥索引获取私钥
func (Account) NewLockedScript ¶
NewLockedScript 生成锁定脚本
func (Account) NewWitnessScript ¶
func (ap Account) NewWitnessScript(execs ...[]byte) *WitnessScript
NewWitnessScript 生成未带有签名的脚本对象
type AccountInfo ¶
type AccountInfo struct { Num int `json:"num"` //密钥总数 Less int `json:"less"` //需要通过的签名数量 Arb bool `json:"arb"` //是否启用仲裁 != InvalidArb 表示启用 Pks []string `json:"pks"` //公钥ID Desc string `json:"desc"` //描述 Type int `json:"type"` //类型 1-金额账户,2-临时账户,可能会被删除 }
密钥证书存储库 AccountInfo 地址账户,值使用公钥hash256生成地址 无需加密,只是用来保存地址生成数据,是否有控制权需要另外检测
func NewTempAccountInfo ¶
创建零时账户
func (AccountInfo) Check ¶
func (ka AccountInfo) Check() error
func (*AccountInfo) Decode ¶
func (ka *AccountInfo) Decode(bb []byte) error
func (AccountInfo) Encode ¶
func (ka AccountInfo) Encode() ([]byte, error)
func (AccountInfo) GetArb ¶
func (ka AccountInfo) GetArb() uint8
func (AccountInfo) ID ¶
func (ka AccountInfo) ID() (Address, error)
func (AccountInfo) MustAddress ¶
func (ka AccountInfo) MustAddress() Address
type AccountJSON ¶
type AccountJSON struct { Num uint8 `json:"num"` Less uint8 `json:"less"` Arb uint8 `json:"arb"` Pubs []string `json:"pubs"` Pris []string `json:"pris"` }
AccountJSON 账户导出结构
type Address ¶
type Address string
Address 账号地址
const ( //EmptyAddress 空地址定义 EmptyAddress Address = "" )
func GetAddressWithID ¶
GetAddressWithID 根据多个公钥ID生成地址
type Alphabet ¶
type Alphabet struct {
// contains filtered or unexported fields
}
Alphabet The base58 alphabet object.
func NewAlphabet ¶
NewAlphabet create a custom alphabet from 58-length string. Note: len(rune(alphabet)) must be 58.
type BIndexIter ¶
type BIndexIter struct {
// contains filtered or unexported fields
}
BIndexIter 区块链迭代器
func (*BIndexIter) SeekHeight ¶
func (it *BIndexIter) SeekHeight(h uint32, skip ...int) bool
SeekHeight 定位到某个高度
type BlockHeader ¶
type BlockHeader struct { Ver uint32 //block ver Prev HASH256 //pre block hash Merkle HASH256 //txs Merkle tree hash Time uint32 //时间戳 Bits uint32 //难度 Nonce uint32 //随机值 // contains filtered or unexported fields }
BlockHeader 区块头
func (BlockHeader) String ¶
func (v BlockHeader) String() string
type BlockIndex ¶
type BlockIndex struct {
// contains filtered or unexported fields
}
BlockIndex 区块链结构
func NewTestBlockIndex ¶
func NewTestBlockIndex(num int) *BlockIndex
NewTestBlockIndex 创建一个测试用区块索引 num创建num个区块
func (*BlockIndex) CalcBits ¶
func (bi *BlockIndex) CalcBits(height uint32) uint32
CalcBits 计算当前区块高度对应的难度
func (*BlockIndex) GetBestValue ¶
func (bi *BlockIndex) GetBestValue() BestValue
GetBestValue 获取最高块信息
func (*BlockIndex) GetBlockConfirm ¶
func (bi *BlockIndex) GetBlockConfirm(id HASH256) int
GetBlockConfirm 获取区块的确认数
func (*BlockIndex) GetBlockHeader ¶
func (bi *BlockIndex) GetBlockHeader(id HASH256) (*TBEle, error)
GetBlockHeader 获取块头
func (*BlockIndex) GetCoin ¶
func (bi *BlockIndex) GetCoin(pkh HASH160, txid HASH256, idx VarUInt) (*CoinKeyValue, error)
GetCoin 获取一笔金额
func (*BlockIndex) GetCoinWithAddress ¶
func (bi *BlockIndex) GetCoinWithAddress(addr Address, txid HASH256, idx VarUInt) (*CoinKeyValue, error)
GetCoinWithAddress 从指定地址交易idx和输出索引获取金额信息
func (*BlockIndex) GetMsgBlock ¶
func (bi *BlockIndex) GetMsgBlock(id HASH256) (*MsgBlock, error)
GetMsgBlock 获取区块数据返回
func (*BlockIndex) GetMsgGetInv ¶
func (bi *BlockIndex) GetMsgGetInv(msg *MsgGetInv, c *Client)
GetMsgGetInv 获取参数发送相关数据
func (*BlockIndex) GetTxConfirm ¶
func (bi *BlockIndex) GetTxConfirm(id HASH256) int
GetTxConfirm 获取交易确认数(所属区块的确认数)
func (*BlockIndex) HasBlock ¶
func (bi *BlockIndex) HasBlock(id HASH256) (uint32, bool)
HasBlock 是否存在存在返回高度
func (*BlockIndex) HasTxValue ¶
func (bi *BlockIndex) HasTxValue(id HASH256) (bool, error)
HasTxValue 是否存在交易
func (*BlockIndex) LastHeaders ¶
func (bi *BlockIndex) LastHeaders(limit int) Headers
LastHeaders 获取最后的多少个区块头
func (*BlockIndex) LinkBlk ¶
func (bi *BlockIndex) LinkBlk(blk *BlockInfo) error
LinkBlk 更新区块数据(需要区块头先链接好
func (*BlockIndex) ListCoins ¶
func (bi *BlockIndex) ListCoins(addr Address) (*CoinsState, error)
ListCoins 获取某个地址账号的金额
func (*BlockIndex) ListCoinsWithAccount ¶
func (bi *BlockIndex) ListCoinsWithAccount(acc *Account) (*CoinsState, error)
ListCoinsWithAccount 根据账号获取金额
func (*BlockIndex) ListCoinsWithCB ¶
func (bi *BlockIndex) ListCoinsWithCB(addr Address, cb func(ckv *CoinKeyValue) bool) error
cb返回false,不再继续获取
func (*BlockIndex) ListCoinsWithID ¶
func (bi *BlockIndex) ListCoinsWithID(pkh HASH160) (Coins, error)
ListCoinsWithID 获取某个id的所有余额 已经消费在内存中的不列出
func (*BlockIndex) ListTxs ¶
func (bi *BlockIndex) ListTxs(addr Address, limit ...int) (TxIndexs, error)
ListTxs 获取某个地址相关的交易
func (*BlockIndex) ListTxsWithID ¶
func (bi *BlockIndex) ListTxsWithID(id HASH160, limit ...int) (TxIndexs, error)
ListTxsWithID 获取交易
func (*BlockIndex) LoadAll ¶
func (bi *BlockIndex) LoadAll(limit int, fn func(pv uint)) error
LoadAll 加载所有链meta f进度回调 0-100
func (*BlockIndex) LoadBlock ¶
func (bi *BlockIndex) LoadBlock(id HASH256) (*BlockInfo, error)
LoadBlock 加载区块
func (*BlockIndex) LoadBlockWithH ¶
func (bi *BlockIndex) LoadBlockWithH(h int) (*BlockInfo, error)
LoadWithHeight 按高度查询区块
func (*BlockIndex) LoadTxValue ¶
func (bi *BlockIndex) LoadTxValue(id HASH256) (*TxValue, error)
LoadTxValue 获取交易所在的区块和位置
func (*BlockIndex) NewBlock ¶
func (bi *BlockIndex) NewBlock(ver uint32) (*BlockInfo, error)
NewBlock 创建下一个高度基本数据
func (*BlockIndex) NewMsgGetBlock ¶
func (bi *BlockIndex) NewMsgGetBlock(id HASH256) MsgIO
NewMsgGetBlock 创建区块网络消息
func (*BlockIndex) NewMsgHeaders ¶
func (bi *BlockIndex) NewMsgHeaders(msg *MsgGetBlock) *MsgHeaders
NewMsgHeaders 创建证据区块头信息 默认获取30个区块头,如果分叉超过30个区块需要另外处理
func (*BlockIndex) NewMsgTxMerkle ¶
func (bi *BlockIndex) NewMsgTxMerkle(id HASH256) (*MsgTxMerkle, error)
NewMsgTxMerkle 返回某个交易的merkle验证树
func (*BlockIndex) NewMsgVersion ¶
func (bi *BlockIndex) NewMsgVersion() *MsgVersion
NewMsgVersion 在链上生成一个版本数据包
func (*BlockIndex) NewTrans ¶
func (bi *BlockIndex) NewTrans(lis ITransListener) *Trans
NewTrans 创建待回调的交易对象
func (*BlockIndex) ReadBlock ¶
func (bi *BlockIndex) ReadBlock(id HASH256) ([]byte, error)
ReadBlock 读取区块数据
func (*BlockIndex) RemoveBestValue ¶
func (bi *BlockIndex) RemoveBestValue() error
RemoveBestValue 移除数据库中的最新区块信息
func (*BlockIndex) Unlink ¶
func (bi *BlockIndex) Unlink(hds Headers) error
Unlink 根据证据区块链修正本地链,回退到一个指定id重新链接
func (*BlockIndex) UnlinkCount ¶
func (bi *BlockIndex) UnlinkCount(id HASH256) (uint32, error)
UnlinkCount 返回需要断开的区块数量
func (*BlockIndex) UnlinkTo ¶
func (bi *BlockIndex) UnlinkTo(id HASH256) error
UnlinkTo 必须从最后开始断开,回退到指定id,不包括id
type BlockInfo ¶
type BlockInfo struct { Header BlockHeader //区块头 Txs []*TX //交易记录,类似比特币 Meta *TBEle //指向链节点 // contains filtered or unexported fields }
BlockInfo txs交易部分和比特币类似 块大小限制为4M大小
func (*BlockInfo) AddTxs ¶
func (blk *BlockInfo) AddTxs(bi *BlockIndex, txs []*TX) error
AddTxs 添加多个交易 有重复消费输出将会失败
func (*BlockInfo) Check ¶
func (blk *BlockInfo) Check(bi *BlockIndex, csp bool) error
Check 检查区块数据 csp 是否检查消费输出
func (*BlockInfo) CheckCoinbase ¶
CheckCoinbase 检测coinbas
func (*BlockInfo) CheckRefsTx ¶
func (blk *BlockInfo) CheckRefsTx(bi *BlockIndex, tx *TX) error
CheckRefsTx 检查引用的tx是否存在区块中
func (*BlockInfo) CheckRepCostTxOut ¶
func (blk *BlockInfo) CheckRepCostTxOut(bi *BlockIndex) error
CheckRepCostTxOut 检查是否有多个输入消费同一个输出
func (*BlockInfo) CheckTxs ¶
func (blk *BlockInfo) CheckTxs(bi *BlockIndex, csp bool) error
CheckTxs 检查所有的交易 csp 是否检查消费金额是否存在,只有消费此输出得时候才检查,如果对应 的区块已经连接到主链,输出必定被消费了,只需要检查签名
func (*BlockInfo) CoinbaseFee ¶
CoinbaseFee 获取coinse out fee sum
func (*BlockInfo) CoinbaseReward ¶
CoinbaseReward 获取区块奖励
func (*BlockInfo) CoinbaseScript ¶
CoinbaseScript 创建Cosinbase 脚本
func (*BlockInfo) EachOutScript ¶
func (blk *BlockInfo) EachOutScript(fn func(tx *TX, idx int, script *LockedScript))
遍历区块中输出脚本
func (*BlockInfo) EndianHeight ¶
EndianHeight 获取区块高度的二进制
func (BlockInfo) ExecScript ¶
func (blk BlockInfo) ExecScript(bi *BlockIndex) error
ExecScript 执行脚本检测
func (*BlockInfo) GetFee ¶
func (blk *BlockInfo) GetFee(bi *BlockIndex) (Amount, error)
GetFee 获取总的交易费
func (*BlockInfo) GetIncome ¶
func (blk *BlockInfo) GetIncome(bi *BlockIndex) (Amount, error)
GetIncome 获取区块收益
func (*BlockInfo) Verify ¶
func (blk *BlockInfo) Verify(ele *TBEle, bi *BlockIndex) error
Verify 验证区块数据
func (*BlockInfo) Write ¶
func (blk *BlockInfo) Write(bi *BlockIndex) error
func (*BlockInfo) WriteTxsIdx ¶
func (blk *BlockInfo) WriteTxsIdx(bi *BlockIndex, bt *Batch) error
WriteTxsIdx 写入交易索引
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
BloomFilter 布隆过滤器
func NewBloomFilter ¶
func NewBloomFilter(funcs uint32, tweak uint32, filter []byte) (*BloomFilter, error)
NewBloomFilter 创建指定参数的布隆过滤器
func (*BloomFilter) NewMsgFilterLoad ¶
func (b *BloomFilter) NewMsgFilterLoad() *MsgFilterLoad
NewMsgFilterLoad 获取一个过滤器加载消息
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache 缓存器
func NewCache ¶
NewCache Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().
func NewCacheFrom ¶
NewCacheFrom Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than one (or NoExpiration), the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().
NewFrom() also accepts an items map which will serve as the underlying map for the cache. This is useful for starting from a deserialized cache (serialized using e.g. gob.Encode() on c.Items()), or passing in e.g. make(map[string]Item, 500) to improve startup performance when the cache is expected to reach a certain minimum size.
Only the cache's methods synchronize access to this map, so it is not recommended to keep any references to the map around after creating a cache. If need be, the map can be accessed at a later point using c.Items() (subject to the same caveat.)
Note regarding serialization: When using e.g. gob, make sure to gob.Register() the individual types stored in the cache before encoding a map retrieved with c.Items(), and to register those same types before decoding a blob containing an items map.
func (*Cache) Add ¶
Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.
func (*Cache) Decrement ¶
Decrement an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to decrement it by n. To retrieve the decremented value, use one of the specialized methods, e.g. DecrementInt64.
func (*Cache) DecrementFloat ¶
DecrementFloat an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to decrement it by n. Pass a negative number to decrement the value. To retrieve the decremented value, use one of the specialized methods, e.g. DecrementFloat64.
func (*Cache) DecrementFloat32 ¶
DecrementFloat32 an item of type float32 by n. Returns an error if the item's value is not an float32, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementFloat64 ¶
DecrementFloat64 an item of type float64 by n. Returns an error if the item's value is not an float64, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt ¶
DecrementInt an item of type int by n. Returns an error if the item's value is not an int, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt16 ¶
DecrementInt16 an item of type int16 by n. Returns an error if the item's value is not an int16, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt32 ¶
DecrementInt32 an item of type int32 by n. Returns an error if the item's value is not an int32, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt64 ¶
DecrementInt64 an item of type int64 by n. Returns an error if the item's value is not an int64, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementInt8 ¶
DecrementInt8 an item of type int8 by n. Returns an error if the item's value is not an int8, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint ¶
DecrementUint an item of type uint by n. Returns an error if the item's value is not an uint, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint16 ¶
DecrementUint16 an item of type uint16 by n. Returns an error if the item's value is not an uint16, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint32 ¶
DecrementUint32 an item of type uint32 by n. Returns an error if the item's value is not an uint32, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint64 ¶
DecrementUint64 an item of type uint64 by n. Returns an error if the item's value is not an uint64, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUint8 ¶
DecrementUint8 an item of type uint8 by n. Returns an error if the item's value is not an uint8, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DecrementUintptr ¶
DecrementUintptr an item of type uintptr by n. Returns an error if the item's value is not an uintptr, or if it was not found. If there is no error, the decremented value is returned.
func (*Cache) DeleteExpired ¶
func (c *Cache) DeleteExpired()
DeleteExpired all expired items from the cache.
func (*Cache) Get ¶
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (*Cache) GetWithExpiration ¶
GetWithExpiration returns an item and its expiration time from the cache. It returns the item or nil, the expiration time if one is set (if the item never expires a zero value for time.Time is returned), and a bool indicating whether the key was found.
func (*Cache) Increment ¶
Increment an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64, float32 or float64 by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to increment it by n. To retrieve the incremented value, use one of the specialized methods, e.g. IncrementInt64.
func (*Cache) IncrementFloat ¶
IncrementFloat an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to increment it by n. Pass a negative number to decrement the value. To retrieve the incremented value, use one of the specialized methods, e.g. IncrementFloat64.
func (*Cache) IncrementFloat32 ¶
IncrementFloat32 an item of type float32 by n. Returns an error if the item's value is not an float32, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementFloat64 ¶
IncrementFloat64 an item of type float64 by n. Returns an error if the item's value is not an float64, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt ¶
IncrementInt an item of type int by n. Returns an error if the item's value is not an int, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt16 ¶
IncrementInt16 an item of type int16 by n. Returns an error if the item's value is not an int16, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt32 ¶
IncrementInt32 an item of type int32 by n. Returns an error if the item's value is not an int32, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt64 ¶
IncrementInt64 an item of type int64 by n. Returns an error if the item's value is not an int64, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementInt8 ¶
IncrementInt8 an item of type int8 by n. Returns an error if the item's value is not an int8, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint ¶
IncrementUint an item of type uint by n. Returns an error if the item's value is not an uint, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint16 ¶
IncrementUint16 an item of type uint16 by n. Returns an error if the item's value is not an uint16, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint32 ¶
IncrementUint32 an item of type uint32 by n. Returns an error if the item's value is not an uint32, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint64 ¶
IncrementUint64 an item of type uint64 by n. Returns an error if the item's value is not an uint64, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUint8 ¶
IncrementUint8 an item of type uint8 by n. Returns an error if the item's value is not an uint8, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) IncrementUintptr ¶
IncrementUintptr an item of type uintptr by n. Returns an error if the item's value is not an uintptr, or if it was not found. If there is no error, the incremented value is returned.
func (*Cache) ItemCount ¶
ItemCount Returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.
func (*Cache) Items ¶
Items , Copies all unexpired items in the cache into a new map and returns it.
func (*Cache) Load ¶
Load . Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist (and haven't expired) in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (*Cache) LoadFile ¶
LoadFile , Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (*Cache) OnEvicted ¶
OnEvicted Sets an (optional) function that is called with the key and value when an item is evicted from the cache. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (*Cache) Replace ¶
Replace Set a new value for the cache key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.
func (*Cache) Save ¶
Save , Write the cache's items (using Gob) to an io.Writer.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (*Cache) SaveFile ¶
SaveFile the cache's items to the given filename, creating the file if it doesn't exist, and overwriting it if it does.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (*Cache) Set ¶
Set Add an item to the cache, replacing any existing item. If the duration is 0 (DefaultExpiration), the cache's default expiration time is used. If it is -1 (NoExpiration), the item never expires.
func (*Cache) SetDefault ¶
SetDefault Add, an item to the cache, replacing any existing item, using the default expiration.
type Client ¶
type Client struct { *NetStream Addr NetAddr Ver uint32 //节点版本 Service uint32 //节点提供的服务 Height uint32 //节点区块高度 // contains filtered or unexported fields }
Client 连接客户端类型定义
func (*Client) GetFilter ¶
func (c *Client) GetFilter() (*BloomFilter, bool)
GetFilter 获取连接上的过滤器 不存在返回nil,false
func (*Client) LoadFilter ¶
LoadFilter 设置过滤器
type ClientMsg ¶
type ClientMsg struct {
// contains filtered or unexported fields
}
ClientMsg 是网络消息通道数据类型
type CoinKeyValue ¶
type CoinKeyValue struct { CPkh HASH160 //公钥hash TxID HASH256 //交易id Index VarUInt //输出索引 Value Amount //输出金额 Base uint8 //是否属于coinbase o or 1 Height VarUInt //所在区块高度 // contains filtered or unexported fields }
CoinKeyValue 金额存储结构
func (CoinKeyValue) IsMatured ¶
func (tk CoinKeyValue) IsMatured(spent uint32) bool
IsMatured 是否成熟可用
func (CoinKeyValue) NewTxIn ¶
func (tk CoinKeyValue) NewTxIn(wits *WitnessScript) (*TxIn, error)
NewTxIn 创建一个消费输入
func (CoinKeyValue) SpentKey ¶
func (tk CoinKeyValue) SpentKey() []byte
SpentKey 消费key,用来记录输入对应的输出是否已经被消费
type Coins ¶
type Coins []*CoinKeyValue
Coins 金额记录
type Config ¶
type Config struct { Name string `json:"name"` //配置文件名称 Confirms uint32 `json:"confirms"` //安全确认数 = 6 MinerNum int `json:"miner_num"` //挖掘机数量,=0不会启动协程挖矿 MaxConn int `json:"max_conn"` //最大激活的连接,包括连入和连出的 Seeds []string `json:"seeds"` //dns seed服务器 DataDir string `json:"data_dir"` //数据路径 Genesis string `json:"genesis"` //第一个区块 LogFile string `json:"log_file"` //日志文件路径 PowTime uint `json:"pow_time"` //14 * 24 * 60 * 60=1209600 PowLimit string `json:"pow_limit"` //最小难度设置 PowSpan uint32 `json:"pow_span"` //难度计算间隔 2016 Halving int `json:"halving"` //210000减产配置 Ver uint32 `json:"version"` //节点版本 TCPPort int `json:"tcp_port"` //服务端口和ip TCPIp string `json:"tcp_ip"` //节点远程连接ip LimitHash UINT256 `json:"-"` //最小工作难度 Nodes []string `json:"nodes"` //配置的可用节点 // contains filtered or unexported fields }
Config 配置加载后只读
func (*Config) GetTCPListenAddr ¶
GetTCPListenAddr 获取服务地址
type CtrlPrivateKeyReq ¶
CtrlPrivateKeyReq 私钥控制权证明请求参数
type CtrlPrivateKeyRes ¶
type CtrlPrivateKeyRes struct { RandStr string //给定的随机字符串 Pks PKBytes //返回私钥对应的公钥 Sig SigBytes //随机字符串签名 }
CtrlPrivateKeyRes 私钥控制权结果
func (CtrlPrivateKeyRes) Check ¶
func (res CtrlPrivateKeyRes) Check(req *CtrlPrivateKeyReq) error
检测是否签名正确
type DBImp ¶
type DBImp interface { Has(ks ...[]byte) (bool, error) //key是否存在 Put(ks ...[]byte) error //添加键值 Get(ks ...[]byte) ([]byte, error) //根据key获取值 Del(ks ...[]byte) error //删除key Write(b *Batch, sync ...bool) error //批量写 Compact(r *Range) error //合并 Close() //关闭数据库 Iterator(slice ...*Range) *Iterator //搜索 Sync() //同步到磁盘 SizeOf(r []*Range) ([]int64, error) //获取范围内数量 Transaction() (TRImp, error) //创建事务 NewBatch() *Batch //创建批量 LoadBatch(d []byte) (*Batch, error) //加载批量数据 }
DBImp 数据基本操作接口
type Document ¶
type Document struct { ID DocumentID //文档ID Tags []string //标签 TxID HASH256 //文档对应交易ID Index VarUInt //文档对应的输出索引 Body VarBytes //内容 Next DocumentID //下个关系 Prev DocumentID //上个关系 }
Document 文档关键字查询存储系统 next prev为存在链式关系时启用
func NewDocument ¶
func NewDocument() *Document
type DocumentID ¶
type DocumentID [12]byte
第一个字节为分类字节,可分0-254类
var NilDocumentID DocumentID
func DocumentIDFromHex ¶
func DocumentIDFromHex(s string) DocumentID
func NewDocumentID ¶
func NewDocumentID(typ ...byte) DocumentID
func NewDocumentIDFrom ¶
func NewDocumentIDFrom(b []byte) DocumentID
func NewDocumentIDFromTimestamp ¶
func NewDocumentIDFromTimestamp(typ byte, timestamp time.Time) DocumentID
func (*DocumentID) Decode ¶
func (id *DocumentID) Decode(r IReader) error
func (DocumentID) Encode ¶
func (id DocumentID) Encode(w IWriter) error
func (DocumentID) Equal ¶
func (id DocumentID) Equal(v DocumentID) bool
func (DocumentID) MarshalJSON ¶
func (id DocumentID) MarshalJSON() ([]byte, error)
func (DocumentID) String ¶
func (id DocumentID) String() string
func (*DocumentID) UnmarshalJSON ¶
func (id *DocumentID) UnmarshalJSON(b []byte) error
type HASH160 ¶
type HASH160 [20]byte
HASH160 公钥HASH160
func DecodeAddressWithPrefix ¶
DecodeAddressWithPrefix 编码地址用指定前缀
type HASH256 ¶
type HASH256 [32]byte
HASH256 bit256 hash
func DecodePublicHash ¶
DecodePublicHash 解码公钥hash
type HashCacher ¶
type HashCacher struct {
// contains filtered or unexported fields
}
HashCacher hash 缓存
type Headers ¶
type Headers []BlockHeader
Headers 区块头集合
type IBlkStore ¶
type IBlkStore interface { //同步数据 Sync() //关闭数据库 Close() //初始化 Init(arg ...interface{}) //索引数据库 Index() DBImp //区块数据文件 Blk() IChunkStore //事物回退文件 Rev() IChunkStore }
IBlkStore 区块存储
type IChunkStore ¶
type IChunkStore interface { Read(st BlkChunk) ([]byte, error) Write(b []byte) (BlkChunk, error) Close() Init() error Sync(id ...uint32) }
IChunkStore 数据块存储
type IDocIter ¶
type IDocIter interface { //遍历文档 Each(fn func(doc *Document) error) error //跳过文档 Skip(skip int) IDocIter //限制数量 Limit(limit int) IDocIter //是否查询包含的所有tags 有损一点性能 Tags(v bool) IDocIter //ByNext 向下迭代 ByNext() IDocIter //ByPrev 向上迭代 ByPrev() IDocIter //获取最后一个key LastKey() []byte //设置lastkey SetLastKey(lk []byte) }
type IDocSystem ¶
type IDocSystem interface { //追加tag AddTag(id DocumentID, tags ...string) error //删除tag DelTag(id DocumentID, tags ...string) error //添加文档 Insert(doc ...*Document) error //删除文档 Delete(id ...DocumentID) error //更新文档 Update(doc ...*Document) error //根据id获取文档内容 qtag是否查询tags Get(id DocumentID, qtag ...bool) (*Document, error) //文档是否存在 Has(id DocumentID) (bool, error) //固定key查询 Find(key string) IDocIter //获取所有文档 prefix存在时拼接前缀 All(prefix ...[]byte) IDocIter //按前缀查询文档 Prefix(key string) IDocIter //模糊查询文档使用正则 Regex(str string) IDocIter //写入磁盘 Sync() //关闭文件系统 Close() }
标签索引库接口
func OpenDocSystem ¶
func OpenDocSystem(dir string) (IDocSystem, error)
OpenDocSystem 打开文档系统,不存在自动创建
type IGetSigBytes ¶
IGetSigBytes 获取签名数据接口
type IKeysDB ¶
type IKeysDB interface { Sync() //关闭密钥数据库 Close() //创建一个1-1账号返回描述信息 NewAccountInfo(typ int, desc string) (*AccountInfo, error) //创建一个新的私钥 NewPrivateKey() (string, error) //获取一个私钥 LoadPrivateKey(id string) (*PrivateKey, error) //保存账户地址描述 SaveAccountInfo(ka *AccountInfo) (Address, error) //加载账户地址描述 LoadAccountInfo(id Address) (*AccountInfo, error) //是否有私钥控制权 HasKeyPrivileges(req *CtrlPrivateKeyReq) (*CtrlPrivateKeyRes, error) //创建待签名脚本 NewWitnessScript(id Address, execs ...[]byte) (*WitnessScript, error) //创建锁定脚本 NewLockedScript(id Address, meta []byte, exec ...[]byte) (*LockedScript, error) //签名并填充脚本数据 Sign(id Address, data []byte, wits *WitnessScript) error //签名指定的账户信息 SignAccount(ka *AccountInfo, data []byte, wits *WitnessScript) error //删除私钥 DeletePrivateKey(id string) error //删除账户描述 DeleteAccountInfo(id Address) error //设置密钥ttl为过期时间 SetKey(key string, ttl time.Duration) //列出地址 ListAddress(limit int, skey ...[]byte) ([]Address, []byte) //列出私钥id ListPrivate(limit int, skey ...[]byte) ([]string, []byte) //添加配置 PutConfig(id string, v []byte) error //获取配置 GetConfig(id string) ([]byte, error) //是否存在配置 HasConfig(id string) (bool, error) //RSA密钥存储 NewRSA() (string, error) HasRSA(id string) (bool, error) ListRSA() []string GetRSA(id string) (*RSAPrivateKey, error) }
type IListener ¶
type IListener interface { //首次初始化时在加载区块链之前 OnInit(bi *BlockIndex) error //时间戳发生器 TimeNow() uint32 //当一个区块断开后 OnUnlinkBlock(blk *BlockInfo) //更新区块数据成功时 OnLinkBlock(blk *BlockInfo) //当块创建时,可以添加,修改块内信息 OnNewBlock(blk *BlockInfo) error //完成区块,当检测完成调用,设置merkle之前 OnFinished(blk *BlockInfo) error //当加载交易列表到区块时可用此方法过滤不加入区块的 //调用 AddTxs 时会触发 OnLoadTxs(txs []*TX) []*TX //链关闭时 OnClose() //当服务启动后会调用一次,区块链,节点服务启动后 OnStart() //系统结束时 OnStop() //当交易进入交易池之前,返回错误不会进入交易池 OnTxPool(tx *TX) error //当交易池的交易被替换时 OnTxPoolRep(old *TX, new *TX) //返回矿工账号,如果返回将优先使用这个地址 MinerAddr() Address }
IListener 所有回调可能来自不同的协程
type IMiner ¶
type IMiner interface { //开始工作 Start(ctx context.Context, lis IListener) //停止 Stop() //等待停止 Wait() //获取区块头 GetHeader() ([]byte, error) //设置区块头 SetHeader(b []byte) error //重新开始计算区块 ResetMiner() error //当前时间戳 TimeNow() uint32 //发送创建新区块请求 NewBlock(ver uint32) }
IMiner 矿工接口
type INetStream ¶
type INetStream interface { ReadMsg() (MsgIO, error) WriteMsg(m MsgIO) error IReadWriter io.Closer }
INetStream 网络流接口
type IReadWriter ¶
IReadWriter 数据流读写接口
type IReader ¶
type IReader interface { io.Reader io.ByteReader TRead(data interface{}) error ReadFull(dp []byte) error }
IReader 数据流读接口
type ISerializable ¶
type IServer ¶
type IServer interface { Start(ctx context.Context, lis IListener) Stop() Wait() NewClient() *Client //广播消息,根据包ID先发包头 BroadMsg(m MsgIO, skips ...*Client) int //直接广播数据,不处理包ID Broadcast(m MsgIO, skips ...*Client) int // DoOpt(opt int) Clients() []*Client Addrs() []*AddrNode }
IServer 服务器接口
type ISigner ¶
type ISigner interface { //签名校验 Verify(bi *BlockIndex) error //签名生成解锁脚本 Sign(bi *BlockIndex, lis ISignTx, pass ...string) error //获取签名hash GetSigHash() ([]byte, error) //获取签名对象 当前交易,当前输入,输入引用的输出,输入在交易中的索引 GetObjs() (*TX, *TxIn, *TxOut, int) //检测签名 脚本调用 VerifySign() error //验证地址 脚本调用 VerifyAddr() error //查找交易中是否包含指定输出的地址 QueryTxOut(addr Address) (*TxOut, error) //查找交易中是否包含指定输入的地址 QueryTxIn(addr Address) (*TxIn, error) }
ISigner 签名验证接口
type ITransListener ¶
type ITransListener interface { //创建输入脚本 NewWitnessScript(ckv *CoinKeyValue) (*WitnessScript, error) //获取使用的金额列表 amt=当前需要的金额 GetCoins(amt Amount) Coins }
ITransListener 转账监听器 先获取可使用的金额,然后获取金额相关的账户用来签名 根据转出地址获取扩展数据,剩下的金额转到找零地址
type IWriter ¶
type IWriter interface { io.Writer io.ByteWriter TWrite(data interface{}) error Len() int Bytes() []byte Reset() WriteFull(dp []byte) error }
IWriter 数据流写接口
type LockedScript ¶
type LockedScript struct { Type uint8 //类型 Pkh HASH160 //地址hash Meta VarBytes //信息数据 len < MaxMetaSize Exec VarBytes //解锁执行脚本 }
LockedScript 标准锁定脚本
func NewLockedScript ¶
func NewLockedScript(pkh HASH160, meta []byte, execs ...[]byte) (*LockedScript, error)
NewLockedScript 创建锁定脚本
type MerkleTree ¶
type MerkleTree struct {
// contains filtered or unexported fields
}
MerkleTree 默克尔树
func GetMerkleTree ¶
func GetMerkleTree(num int, hashs []HASH256, vb *BitSet) *MerkleTree
GetMerkleTree 从数据返回默克尔树
func (*MerkleTree) Build ¶
func (tree *MerkleTree) Build(ids []HASH256, vb *BitSet) *MerkleTree
Build 构建
func (*MerkleTree) CalcHash ¶
func (tree *MerkleTree) CalcHash(height int, pos int, ids []HASH256) HASH256
CalcHash 结算hash
func (*MerkleTree) Extract ¶
func (tree *MerkleTree) Extract() (HASH256, []HASH256, []int)
Extract 导出根和节点
func (*MerkleTree) ExtractRoot ¶
func (tree *MerkleTree) ExtractRoot() (HASH256, error)
ExtractRoot 导出默克尔根
type MinerGroup ¶
type MinerGroup struct {
// contains filtered or unexported fields
}
MinerGroup 计算群组
func NewMinerGroup ¶
func NewMinerGroup(hb HeaderBytes, bits uint32, num int) *MinerGroup
NewMinerGroup 新建一个计算任务
type MsgBroadPkg ¶
MsgBroadPkg 广播头
type MsgFilterLoad ¶
MsgFilterLoad 设置过滤器,调用后client的bloom生效 过滤器设置后只会提交符合条件的信息给客户端
type MsgGetBlock ¶
MsgGetBlock 获取区块消息
type MsgHeaders ¶
type MsgHeaders struct { Headers Headers //上次请求参数 Info MsgGetBlock }
MsgHeaders 获取区块头网络结构
type MsgIO ¶
type MsgIO interface { ISerializable ID() (MsgID, error) //广播id获取 Type() NTType }
MsgIO 协议消息
type MsgTxMerkle ¶
type MsgTxMerkle struct { TxID HASH256 //当前交易id Trans VarInt //交易锁在块的交易数量 Hashs []HASH256 //基于merkle树的验证hash Bits VarBytes // }
MsgTxMerkle 返回交易验证merkle树
type MsgVersion ¶
type MsgVersion struct { Ver uint32 //版本 Service uint32 //服务 Addr NetAddr //节点外网地址 Height uint32 //节点区块高度 NodeID uint64 //节点id Tps VarUInt //交易池数量 }
MsgVersion 版本消息包
type NetAddr ¶
type NetAddr struct {
// contains filtered or unexported fields
}
NetAddr 地址定义
func (NetAddr) IsGlobalUnicast ¶
IsGlobalUnicast 是否是有效的可链接的地址
type NetPackage ¶
type NetPackage struct { Flags [4]byte //标识 Type NTType //包类型 Bytes VarBytes //数据长度 Attr uint8 //数据特性 Sum uint32 //校验和 }
NetPackage 网络数据包定义
type PrivateKey ¶
PrivateKey 私钥
func LoadPrivateKey ¶
func LoadPrivateKey(s string, pass ...string) (*PrivateKey, error)
LoadPrivateKey 加载私钥
func NewPrivateKeyWithBytes ¶
func NewPrivateKeyWithBytes(b []byte) (*PrivateKey, error)
NewPrivateKeyWithBytes 使用二进制创建私钥
func (PrivateKey) String ¶
func (pk PrivateKey) String() string
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub is a collection of topics.
func NewPubSub ¶
NewPubSub creates a new PubSub and starts a goroutine for handling operations. The capacity of the channels created by Sub and SubOnce will be as specified.
func (*PubSub) AddSubOnceEach ¶
AddSubOnceEach adds subscriptions to an existing channel with SubOnceEach behavior.
func (*PubSub) Close ¶
Close closes all channels currently subscribed to the specified topics. If a channel is subscribed to multiple topics, some of which is not specified, it is not closed.
func (*PubSub) Shutdown ¶
func (ps *PubSub) Shutdown()
Shutdown closes all subscribed channels and terminates the goroutine.
func (*PubSub) Sub ¶
Sub returns a channel on which messages published on any of the specified topics can be received.
func (*PubSub) SubOnce ¶
SubOnce is similar to Sub, but only the first message published, after subscription, on any of the specified topics can be received.
func (*PubSub) SubOnceEach ¶
SubOnceEach returns a channel on which callers receive, at most, one message for each topic.
func (*PubSub) TryPub ¶
TryPub publishes the given message to all subscribers of the specified topics if the topic has buffer space.
func (*PubSub) Unsub ¶
Unsub unsubscribes the given channel from the specified topics. If no topic is specified, it is unsubscribed from all topics.
Unsub must be called from a goroutine that is different from the subscriber. The subscriber must consume messages from the channel until it reaches the end. Not doing so can result in a deadlock.
type PublicKey ¶
PublicKey 公钥
func LoadPublicKey ¶
LoadPublicKey 加载公钥数据
type RSAPrivateKey ¶
type RSAPrivateKey struct {
// contains filtered or unexported fields
}
RSAPrivateKey rsa私钥
func LoadRSAPrivateKey ¶
func LoadRSAPrivateKey(str string, pass ...string) (*RSAPrivateKey, error)
LoadRSAPrivateKey 加载一个私钥
func (RSAPrivateKey) Decrypt ¶
func (ptr RSAPrivateKey) Decrypt(bb []byte) ([]byte, error)
Decrypt 私钥解密
func (*RSAPrivateKey) Load ¶
func (ptr *RSAPrivateKey) Load(str string, pass ...string) error
Load 加载rsa私钥
func (RSAPrivateKey) PublicKey ¶
func (ptr RSAPrivateKey) PublicKey() *RSAPublicKey
PublicKey 获取对应的公钥
type RSAPublicKey ¶
type RSAPublicKey struct {
// contains filtered or unexported fields
}
RSAPublicKey rsa公钥
func LoadRSAPublicKey ¶
func LoadRSAPublicKey(str string) (*RSAPublicKey, error)
LoadRSAPublicKey 加载一个公钥
func (RSAPublicKey) Encrypt ¶
func (ptr RSAPublicKey) Encrypt(bb []byte) ([]byte, error)
Encrypt 公钥加密
func (RSAPublicKey) ID ¶
func (ptr RSAPublicKey) ID() (string, error)
func (RSAPublicKey) MustID ¶
func (ptr RSAPublicKey) MustID() string
type Script ¶
type Script []byte
Script 脚本定义
func NewCoinbaseScript ¶
NewCoinbaseScript 创建coinbase脚本
func NewTxScript ¶
NewTxScript 创建交易脚本
type TBEle ¶
TBEle 索引头
func EmptyTBEle ¶
func EmptyTBEle(h uint32, bh BlockHeader, bi *BlockIndex) *TBEle
EmptyTBEle 创建一个空的链表结构
type TBMeta ¶
type TBMeta struct { BlockHeader //区块头 Txs VarUInt //tx数量 Blk BlkChunk //数据状态 Rev BlkChunk //日志回退 // contains filtered or unexported fields }
TBMeta 区块头存储类型
type TCPServer ¶
type TCPServer struct {
// contains filtered or unexported fields
}
TCPServer 基于tcp的服务
func (*TCPServer) IsAddrOpen ¶
IsAddrOpen 地址是否已经链接
func (*TCPServer) NewClientWithConn ¶
NewClientWithConn 从网络连接创建客户端
func (*TCPServer) NewMsgAddrs ¶
NewMsgAddrs 创建地址列表消息
type TRImp ¶
type TRImp interface { Has(ks ...[]byte) (bool, error) Put(ks ...[]byte) error Get(ks ...[]byte) ([]byte, error) Del(ks ...[]byte) error Write(b *Batch, sync ...bool) error Iterator(slice ...*Range) *Iterator Commit() error Discard() }
TRImp 事务接口
type TX ¶
type TX struct { Ver VarUInt //版本 Ins []*TxIn //输入 Outs []*TxOut //输出 Script Script //交易执行脚本,执行失败不会进入交易池 // contains filtered or unexported fields }
TX 交易
func (*TX) Check ¶
func (tx *TX) Check(bi *BlockIndex, csp bool) error
Check 检测除coinbase交易外的交易金额 csp是否检测输出金额是否已经被消费,如果交易已经打包进区块,输入引用的输出肯定被消费,coin将不存在 clk 是否检查seqlock
func (*TX) CoinbaseFee ¶
CoinbaseFee 获取coinse out fee sum
func (*TX) ExecScript ¶
func (tx *TX) ExecScript(bi *BlockIndex) error
ExecScript 返回错误交易不进入区块 执行之前已经校验了签名 AddTxs LinkBlk 时会执行这个交易脚本检测
func (*TX) GetFeeAmount ¶
func (tx *TX) GetFeeAmount(bi *BlockIndex) (Amount, error)
GetFeeAmount 获取此交易交易费 如果是coinase返回coinbase输出金额
func (*TX) HasRepTxIn ¶
func (tx *TX) HasRepTxIn(bi *BlockIndex, csp bool) bool
HasRepTxIn 检测交易中是否有重复的输入
type TestLis ¶
type TestLis struct {
// contains filtered or unexported fields
}
TestLis 测试用监听器
func (*TestLis) OnClientMsg ¶
当收到网络数据时,数据包根据类型转换成需要的包
func (*TestLis) OnFinished ¶
完成区块,当检测完成调用,设置merkle之前
func (*TestLis) OnUnlinkBlock ¶
type Trans ¶
type Trans struct { Dst []Address //目标地址 Amt []Amount //目标金额 大小与dst对应 Metas []string Fee Amount //交易费 // contains filtered or unexported fields }
Trans 交易数据结构
type TxEvent ¶
type TxEvent struct { Idx *BlockIndex Blk *BlockInfo //如果交易在块中blk != nil Tx *TX }
TxEvent 交易发布订阅参数
type TxIn ¶
type TxIn struct { OutHash HASH256 //输出交易hash OutIndex VarUInt //对应的输出索引 Script Script //签名后填充脚本 Sequence VarUInt //连续号 }
TxIn 交易输入
func (TxIn) GetCoin ¶
func (in TxIn) GetCoin(bi *BlockIndex) (*CoinKeyValue, error)
GetCoin 获取引用的coin
type TxIndex ¶
type TxIndex struct { TxID HASH256 Height uint32 Value TxValue // contains filtered or unexported fields }
TxIndex 用户交易索引
type TxOut ¶
type TxOut struct { Value Amount //输出金额 Script Script //锁定脚本 // contains filtered or unexported fields }
TxOut 交易输出
func (*TxOut) GetCoin ¶
func (out *TxOut) GetCoin(in *TxIn, bi *BlockIndex) (*CoinKeyValue, error)
GetCoin 获取输入引用的输出 这个输出相关的金额信息
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool 交易池,存放签名成功,未确认的交易 当区块连接后需要把区块中的交易从这个池子删除 交易池加入交易后会记录消费输出,也会记录交易池中可用的金额
func (*TxPool) GetDelTxs ¶
func (pool *TxPool) GetDelTxs(bi *BlockIndex, txs []*TX) []*TX
GetDelTxs 返回已经删除的引用的交易
func (*TxPool) IsSpentCoin ¶
func (pool *TxPool) IsSpentCoin(coin *CoinKeyValue) bool
IsSpentCoin 一笔钱是否已经在内存交易池中某个交易消费
func (*TxPool) ListTxsWithID ¶
ListTxsWithID 获取spkh相关的交易
func (*TxPool) LoadTxsWithBlk ¶
func (pool *TxPool) LoadTxsWithBlk(bi *BlockIndex, blk *BlockInfo) ([]*TX, error)
LoadTxsWithBlk 取出符合区块blk的交易,大小不能超过限制
func (*TxPool) NewMsgGetTxPool ¶
func (pool *TxPool) NewMsgGetTxPool() *MsgGetTxPool
NewMsgGetTxPool 发送获取交易池所有的交易ID
func (*TxPool) NewMsgTxPool ¶
func (pool *TxPool) NewMsgTxPool(m *MsgGetTxPool) *MsgTxPool
NewMsgTxPool 获取交易池数据,并忽略对方有的交易
func (*TxPool) PushTx ¶
func (pool *TxPool) PushTx(bi *BlockIndex, tx *TX) error
PushTx 添加进去一笔交易放入最后 交易必须是校验过的
func (*TxPool) PushTxs ¶
func (pool *TxPool) PushTxs(bi *BlockIndex, msg *MsgTxPool)
PushTxs 加入其他节点过来的多个交易数据
type TxScript ¶
type TxScript struct { Type uint8 //脚本最大执行时间,时间一半分配给交易脚本,一半分配给签名脚本 //签名脚本每个输入签名只有 n分之一的一半时间 n为输入数量 //单位:毫秒 ExeLimit uint32 //执行脚本 Exec VarBytes }
TxScript 交易脚本
type UINT256 ¶
type UINT256 [UInt256Width]uint32
UINT256 unsigned int hash
func (*UINT256) SetCompact ¶
SetCompact return Negative,Overflow
type WitnessScript ¶
type WitnessScript struct { Type uint8 //SCRIPT_WITNESS_TYPE Num uint8 //签名数量 Less uint8 //至少正确的数量 Arb uint8 //是否启用仲裁 Pks []PKBytes //公钥 Sig []SigBytes //签名 Exec VarBytes //执行脚本 }
WitnessScript 隔离见证脚本
func (WitnessScript) CheckSigs ¶
func (ss WitnessScript) CheckSigs(sigs []SigBytes) error
CheckSigs 检查指定的签名
func (*WitnessScript) Final ¶
func (ss *WitnessScript) Final() (Script, error)
FinalScript 完成脚本,检查并精简脚本,签名完成之后调用
func (WitnessScript) ToAccount ¶
func (ss WitnessScript) ToAccount() (*Account, error)
ToAccount 转换为账户信息
Source Files
¶
- account.go
- aescrypt.go
- amount.go
- base58.go
- bech32.go
- bestvalue.go
- bindex.go
- bitset.go
- block.go
- blockmsg.go
- bloom.go
- cache.go
- chunkstore.go
- client.go
- coins.go
- config.go
- dbstore.go
- exec.go
- filtermsg.go
- flocker.go
- flocker_unix.go
- hash.go
- keysdb.go
- listener.go
- logger.go
- merkle.go
- miner.go
- netmsg.go
- pow.go
- protocol.go
- pubsub.go
- ripemd160.go
- rsacrypt.go
- script.go
- secp256k1.go
- server.go
- sigkey.go
- sign.go
- siphash.go
- store.go
- tagsdb.go
- tapi.go
- trans.go
- txmsg.go
- txpool.go
- util.go
- uuid.go
- xginx.go