Documentation ¶
Overview ¶
* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- Variables
- func BigIntFromNeoBytes(ba []byte) *big.Int
- func BigIntToNeoBytes(data *big.Int) []byte
- func FileExisted(filename string) bool
- func GetNonce() uint64
- func HexToBytes(value string) ([]byte, error)
- func PubKeyFromHex(nodeid string) (keypair.PublicKey, error)
- func PubKeyToHex(pub keypair.PublicKey) string
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func SafeSub(x, y uint64) (uint64, bool)
- func SerializeToBytes(values ...Serializable) []byte
- func ToArrayReverse(arr []byte) []byte
- func ToHexString(data []byte) string
- type Address
- type Fixed64
- type I128
- type InventoryType
- type LimitedWriter
- type Serializable
- type U128
- type Uint256
- type ZeroCopySink
- func (self *ZeroCopySink) BackUp(n uint64)
- func (self *ZeroCopySink) Bytes() []byte
- func (self *ZeroCopySink) NextBytes(n uint64) (data []byte)
- func (self *ZeroCopySink) Reset()
- func (self *ZeroCopySink) Size() uint64
- func (self *ZeroCopySink) WriteAddress(addr Address)
- func (self *ZeroCopySink) WriteBool(data bool)
- func (self *ZeroCopySink) WriteByte(c byte)
- func (self *ZeroCopySink) WriteBytes(p []byte)
- func (self *ZeroCopySink) WriteHash(hash Uint256)
- func (self *ZeroCopySink) WriteI128(i128 I128)
- func (self *ZeroCopySink) WriteInt16(data int16)
- func (self *ZeroCopySink) WriteInt32(data int32)
- func (self *ZeroCopySink) WriteInt64(data int64)
- func (self *ZeroCopySink) WriteString(data string) (size uint64)
- func (self *ZeroCopySink) WriteU128(u128 U128)
- func (self *ZeroCopySink) WriteUint16(data uint16)
- func (self *ZeroCopySink) WriteUint32(data uint32)
- func (self *ZeroCopySink) WriteUint64(data uint64) *ZeroCopySink
- func (self *ZeroCopySink) WriteUint8(data uint8)
- func (self *ZeroCopySink) WriteVarBytes(data []byte) (size uint64)
- func (self *ZeroCopySink) WriteVarUint(data uint64) (size uint64)
- type ZeroCopySource
- func (self *ZeroCopySource) BackUp(n uint64)
- func (self *ZeroCopySource) Len() uint64
- func (self *ZeroCopySource) NextAddress() (data Address, eof bool)
- func (self *ZeroCopySource) NextBool() (data bool, irregular bool, eof bool)
- func (self *ZeroCopySource) NextByte() (data byte, eof bool)
- func (self *ZeroCopySource) NextBytes(n uint64) (data []byte, eof bool)
- func (self *ZeroCopySource) NextHash() (data Uint256, eof bool)
- func (self *ZeroCopySource) NextI128() (data I128, eof bool)
- func (self *ZeroCopySource) NextInt16() (data int16, eof bool)
- func (self *ZeroCopySource) NextInt32() (data int32, eof bool)
- func (self *ZeroCopySource) NextInt64() (data int64, eof bool)
- func (self *ZeroCopySource) NextString() (data string, size uint64, irregular bool, eof bool)
- func (self *ZeroCopySource) NextUint16() (data uint16, eof bool)
- func (self *ZeroCopySource) NextUint32() (data uint32, eof bool)
- func (self *ZeroCopySource) NextUint64() (data uint64, eof bool)
- func (self *ZeroCopySource) NextUint8() (data uint8, eof bool)
- func (self *ZeroCopySource) NextVarBytes() (data []byte, size uint64, irregular bool, eof bool)
- func (self *ZeroCopySource) NextVarUint() (data uint64, size uint64, irregular bool, eof bool)
- func (self *ZeroCopySource) Pos() uint64
- func (self *ZeroCopySource) ReadString() (string, error)
- func (self *ZeroCopySource) ReadUint32() (data uint32, err error)
- func (self *ZeroCopySource) ReadUint64() (data uint64, err error)
- func (self *ZeroCopySource) ReadVarBytes() (data []byte, err error)
- func (self *ZeroCopySource) ReadVarUint() (uint64, error)
- func (self *ZeroCopySource) Size() uint64
- func (self *ZeroCopySource) Skip(n uint64) (eof bool)
Constants ¶
const ( UINT16_SIZE = 2 UINT32_SIZE = 4 UINT64_SIZE = 8 UINT256_SIZE = 32 )
const ADDR_LEN = 20
const (
Decimal = 100000000
)
const I128_SIZE = 16
const (
MAX_UINT64 = math.MaxUint64
)
const MaxBase58AddrLen = 2048 // just to avoid dos
Variables ¶
var ADDRESS_EMPTY = Address{}
var ErrIrregularData = errors.New("irregular data")
var ErrTooLarge = errors.New("bytes.Buffer: too large")
var ErrWriteExceedLimitedCount = errors.New("writer exceed limited count")
var U128_EMPTY = U128{}
var UINT256_EMPTY = Uint256{}
Functions ¶
func BigIntFromNeoBytes ¶
func BigIntToNeoBytes ¶
neo encoding: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.biginteger.tobytearray?view=netframework-4.7.2
func FileExisted ¶
FileExisted checks whether filename exists in filesystem
func HexToBytes ¶
HexToBytes convert hex string to []byte
func PubKeyToHex ¶ added in v1.13.0
func SerializeToBytes ¶ added in v1.8.1
func SerializeToBytes(values ...Serializable) []byte
func ToArrayReverse ¶
Types ¶
type Address ¶
func AddressFromBase58 ¶
AddressFromBase58 returns Address from encoded base58 string
func AddressFromHexString ¶
AddressParseFromHexString returns parsed Address
func AddressFromVmCode ¶ added in v1.5.1
func AddressParseFromBytes ¶
AddressParseFromBytes returns parsed Address
func (*Address) Deserialization ¶ added in v1.8.1
func (self *Address) Deserialization(source *ZeroCopySource) error
Deserialize deserialize Address from io.Reader
func (*Address) Serialization ¶ added in v1.8.1
func (self *Address) Serialization(sink *ZeroCopySink)
Serialize serialize Address into io.Writer
func (*Address) ToHexString ¶
ToHexString returns hex string representation of Address
type Fixed64 ¶
type Fixed64 int64
the 64 bit fixed-point number, precise 10^-8
func FromDecimal ¶
func (*Fixed64) Deserialization ¶ added in v1.6.0
func (f *Fixed64) Deserialization(source *ZeroCopySource) error
func (*Fixed64) Serialization ¶ added in v1.6.0
func (f *Fixed64) Serialization(sink *ZeroCopySink)
type I128 ¶ added in v1.8.0
func I128FromBigInt ¶ added in v1.8.0
val should in i128 range
func I128FromInt64 ¶ added in v1.8.0
func I128FromUint64 ¶ added in v1.8.0
func (*I128) ToNumString ¶ added in v1.8.0
type InventoryType ¶
type InventoryType byte
const ( TRANSACTION InventoryType = 0x01 BLOCK InventoryType = 0x02 CONSENSUS InventoryType = 0xe0 )
type LimitedWriter ¶ added in v0.9.3
type LimitedWriter struct {
// contains filtered or unexported fields
}
func NewLimitedWriter ¶ added in v0.9.3
func NewLimitedWriter(w io.Writer, max uint64) *LimitedWriter
func (*LimitedWriter) Count ¶ added in v0.9.3
func (self *LimitedWriter) Count() uint64
Count function return counted bytes
type Serializable ¶ added in v1.8.1
type Serializable interface {
Serialization(sink *ZeroCopySink)
}
type Uint256 ¶
type Uint256 [UINT256_SIZE]byte
func ComputeMerkleRoot ¶
param hashes will be used as workspace
func Uint256FromHexString ¶
func Uint256ParseFromBytes ¶
func (Uint256) ToHexString ¶
type ZeroCopySink ¶ added in v1.0.3
type ZeroCopySink struct {
// contains filtered or unexported fields
}
func NewZeroCopySink ¶ added in v1.0.3
func NewZeroCopySink(b []byte) *ZeroCopySink
NewReader returns a new ZeroCopySink reading from b.
func (*ZeroCopySink) BackUp ¶ added in v1.0.3
func (self *ZeroCopySink) BackUp(n uint64)
Backs up a number of bytes, so that the next call to NextXXX() returns data again that was already returned by the last call to NextXXX().
func (*ZeroCopySink) Bytes ¶ added in v1.0.3
func (self *ZeroCopySink) Bytes() []byte
func (*ZeroCopySink) NextBytes ¶ added in v1.0.3
func (self *ZeroCopySink) NextBytes(n uint64) (data []byte)
func (*ZeroCopySink) Reset ¶ added in v1.0.3
func (self *ZeroCopySink) Reset()
func (*ZeroCopySink) Size ¶ added in v1.0.3
func (self *ZeroCopySink) Size() uint64
func (*ZeroCopySink) WriteAddress ¶ added in v1.0.3
func (self *ZeroCopySink) WriteAddress(addr Address)
func (*ZeroCopySink) WriteBool ¶ added in v1.0.3
func (self *ZeroCopySink) WriteBool(data bool)
func (*ZeroCopySink) WriteByte ¶ added in v1.0.3
func (self *ZeroCopySink) WriteByte(c byte)
func (*ZeroCopySink) WriteBytes ¶ added in v1.0.3
func (self *ZeroCopySink) WriteBytes(p []byte)
func (*ZeroCopySink) WriteHash ¶ added in v1.0.3
func (self *ZeroCopySink) WriteHash(hash Uint256)
func (*ZeroCopySink) WriteI128 ¶ added in v1.8.0
func (self *ZeroCopySink) WriteI128(i128 I128)
func (*ZeroCopySink) WriteInt16 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteInt16(data int16)
func (*ZeroCopySink) WriteInt32 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteInt32(data int32)
func (*ZeroCopySink) WriteInt64 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteInt64(data int64)
func (*ZeroCopySink) WriteString ¶ added in v1.0.3
func (self *ZeroCopySink) WriteString(data string) (size uint64)
func (*ZeroCopySink) WriteU128 ¶ added in v1.8.0
func (self *ZeroCopySink) WriteU128(u128 U128)
func (*ZeroCopySink) WriteUint16 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteUint16(data uint16)
func (*ZeroCopySink) WriteUint32 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteUint32(data uint32)
func (*ZeroCopySink) WriteUint64 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteUint64(data uint64) *ZeroCopySink
func (*ZeroCopySink) WriteUint8 ¶ added in v1.0.3
func (self *ZeroCopySink) WriteUint8(data uint8)
func (*ZeroCopySink) WriteVarBytes ¶ added in v1.0.3
func (self *ZeroCopySink) WriteVarBytes(data []byte) (size uint64)
func (*ZeroCopySink) WriteVarUint ¶ added in v1.0.3
func (self *ZeroCopySink) WriteVarUint(data uint64) (size uint64)
type ZeroCopySource ¶ added in v1.0.3
type ZeroCopySource struct {
// contains filtered or unexported fields
}
func NewZeroCopySource ¶ added in v1.0.3
func NewZeroCopySource(b []byte) *ZeroCopySource
NewReader returns a new ZeroCopySource reading from b.
func (*ZeroCopySource) BackUp ¶ added in v1.0.3
func (self *ZeroCopySource) BackUp(n uint64)
Backs up a number of bytes, so that the next call to NextXXX() returns data again that was already returned by the last call to NextXXX().
func (*ZeroCopySource) Len ¶ added in v1.0.3
func (self *ZeroCopySource) Len() uint64
Len returns the number of bytes of the unread portion of the slice.
func (*ZeroCopySource) NextAddress ¶ added in v1.0.3
func (self *ZeroCopySource) NextAddress() (data Address, eof bool)
func (*ZeroCopySource) NextBool ¶ added in v1.0.3
func (self *ZeroCopySource) NextBool() (data bool, irregular bool, eof bool)
func (*ZeroCopySource) NextByte ¶ added in v1.0.3
func (self *ZeroCopySource) NextByte() (data byte, eof bool)
ReadByte implements the io.ByteReader interface.
func (*ZeroCopySource) NextBytes ¶ added in v1.0.3
func (self *ZeroCopySource) NextBytes(n uint64) (data []byte, eof bool)
Read implements the io.ZeroCopySource interface.
func (*ZeroCopySource) NextHash ¶ added in v1.0.3
func (self *ZeroCopySource) NextHash() (data Uint256, eof bool)
func (*ZeroCopySource) NextI128 ¶ added in v1.8.0
func (self *ZeroCopySource) NextI128() (data I128, eof bool)
func (*ZeroCopySource) NextInt16 ¶ added in v1.0.3
func (self *ZeroCopySource) NextInt16() (data int16, eof bool)
func (*ZeroCopySource) NextInt32 ¶ added in v1.0.3
func (self *ZeroCopySource) NextInt32() (data int32, eof bool)
func (*ZeroCopySource) NextInt64 ¶ added in v1.0.3
func (self *ZeroCopySource) NextInt64() (data int64, eof bool)
func (*ZeroCopySource) NextString ¶ added in v1.0.3
func (self *ZeroCopySource) NextString() (data string, size uint64, irregular bool, eof bool)
func (*ZeroCopySource) NextUint16 ¶ added in v1.0.3
func (self *ZeroCopySource) NextUint16() (data uint16, eof bool)
func (*ZeroCopySource) NextUint32 ¶ added in v1.0.3
func (self *ZeroCopySource) NextUint32() (data uint32, eof bool)
func (*ZeroCopySource) NextUint64 ¶ added in v1.0.3
func (self *ZeroCopySource) NextUint64() (data uint64, eof bool)
func (*ZeroCopySource) NextUint8 ¶ added in v1.0.3
func (self *ZeroCopySource) NextUint8() (data uint8, eof bool)
func (*ZeroCopySource) NextVarBytes ¶ added in v1.0.3
func (self *ZeroCopySource) NextVarBytes() (data []byte, size uint64, irregular bool, eof bool)
func (*ZeroCopySource) NextVarUint ¶ added in v1.0.3
func (self *ZeroCopySource) NextVarUint() (data uint64, size uint64, irregular bool, eof bool)
func (*ZeroCopySource) Pos ¶ added in v1.0.3
func (self *ZeroCopySource) Pos() uint64
func (*ZeroCopySource) ReadString ¶ added in v1.11.0
func (self *ZeroCopySource) ReadString() (string, error)
func (*ZeroCopySource) ReadUint32 ¶ added in v1.11.0
func (self *ZeroCopySource) ReadUint32() (data uint32, err error)
func (*ZeroCopySource) ReadUint64 ¶ added in v1.14.1
func (self *ZeroCopySource) ReadUint64() (data uint64, err error)
func (*ZeroCopySource) ReadVarBytes ¶ added in v1.11.0
func (self *ZeroCopySource) ReadVarBytes() (data []byte, err error)
func (*ZeroCopySource) ReadVarUint ¶ added in v1.14.1
func (self *ZeroCopySource) ReadVarUint() (uint64, error)
func (*ZeroCopySource) Size ¶ added in v1.0.3
func (self *ZeroCopySource) Size() uint64
Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method.
func (*ZeroCopySource) Skip ¶ added in v1.0.3
func (self *ZeroCopySource) Skip(n uint64) (eof bool)