bitmessage

package
v0.0.0-...-2f776a7 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2011 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WRONGMESSAGE = iota
	VERSION      = iota
	VERACK       = iota
	ADDR         = iota
	INV          = iota
	GETDATA      = iota
	GETBLOCKS    = iota
	GETHEADERS   = iota
	TX           = iota
	BLOCK        = iota
	HEADERS      = iota
	GETADDR      = iota
	CHECKORDER   = iota
	SUBMITORDER  = iota
	REPLY        = iota
	PING         = iota
	ALERT        = iota
)
View Source
const (
	ERROR     uint32 = iota //==0
	MSG_TX    uint32 = iota //==1
	MSG_BLOCK uint32 = iota //==2
)
View Source
const (
	SUCCESS      uint32 = iota //==0 //The IP Transaction can proceed (checkorder), or has been accepted (submitorder)
	WALLET_ERROR uint32 = iota //==1 //AcceptWalletTransaction() failed
	DENIED       uint32 = iota //==2 //IP Transactions are not accepted by this node
)
View Source
const (
	NOT_NODE_NETWORK uint64 = iota //==0
	NODE_NETWORK     uint64 = iota //==1
)
View Source
const MainNetMagic uint32 = 0xD9B4BEF9
View Source
const MainNetPort uint16 = 8333
View Source
const TestNetMagic uint32 = 0xDAB5BFFA
View Source
const TestNetPort uint16 = 18333

Variables

This section is empty.

Functions

func MessageType

func MessageType(Command []byte) int

func TestEverything

func TestEverything()

Types

type AddressList

type AddressList struct {
	Count    uint8
	AddrList []*NetworkAddress
}

checked, works as expected

func (*AddressList) AddAddress

func (al *AddressList) AddAddress(na *NetworkAddress)

func (*AddressList) Clear

func (al *AddressList) Clear()

func (*AddressList) Compile

func (al *AddressList) Compile() []byte

TODO: double check if 30 is really the answer

type BitMessage

type BitMessage struct {
	Magic    [4]byte  //Magic 4 network bytes
	Command  [12]byte //12 ASCII characters identifying package content, NULL padded
	Length   [4]byte  //Length of the Payload
	Checksum [4]byte  //first 4 bytes of sha256(sha256(Payload))
	Payload  []byte   //the actual data
}

func DecodeMessage

func DecodeMessage(msg []byte) *BitMessage

func DeserializeMessages

func DeserializeMessages(msgs []byte) []*BitMessage

func (*BitMessage) Compile

func (bm *BitMessage) Compile() []byte

func (*BitMessage) CompileVerack

func (bm *BitMessage) CompileVerack() []byte

send the special verack message (without Checksum)

func (*BitMessage) CompileVersion

func (bm *BitMessage) CompileVersion() []byte

send the special version message (without Checksum)

func (*BitMessage) GetMagic

func (bm *BitMessage) GetMagic() []byte

func (*BitMessage) GiveMessageType

func (bm *BitMessage) GiveMessageType() int

TODO: test

func (*BitMessage) SetCommand

func (bm *BitMessage) SetCommand(newCommand string)

func (*BitMessage) SetMagic

func (bm *BitMessage) SetMagic(newMagic uint32)

func (*BitMessage) SetPayloadAddr

func (bm *BitMessage) SetPayloadAddr(al *AddressList)

func (*BitMessage) SetPayloadByte

func (bm *BitMessage) SetPayloadByte(pld []byte)

func (*BitMessage) SetPayloadVersion

func (bm *BitMessage) SetPayloadVersion(vm *VersionMessage)

type Block

type Block struct {
	Version    [4]byte
	PrevBlock  [32]byte //char[32]
	MerkleRoot [32]byte //char[32]
	Timestamp  [4]byte
	Bits       [4]byte
	Nonce      [4]byte
	TxnCount   mymath.VarInt
	Txns       []*Tx //tx[]
}

TODO: test

func DecodeBlock

func DecodeBlock(blck []byte) *Block

TODO: do

func GenerateGenesisBlock

func GenerateGenesisBlock() *Block

TODO: check

func (*Block) AddTx

func (b *Block) AddTx(t *Tx)

func (*Block) Clear

func (b *Block) Clear()

func (*Block) Compile

func (b *Block) Compile() []byte

func (*Block) GetBits

func (b *Block) GetBits() []byte

func (*Block) GetHeader

func (b *Block) GetHeader() *BlockHeader

func (*Block) GetMerkleRoot

func (b *Block) GetMerkleRoot() []byte

func (*Block) GetNonce

func (b *Block) GetNonce() []byte

func (*Block) GetPrevBlock

func (b *Block) GetPrevBlock() []byte

func (*Block) GetTimestamp

func (b *Block) GetTimestamp() []byte

func (*Block) GetTxnCount

func (b *Block) GetTxnCount() mymath.VarInt

func (*Block) GetTxns

func (b *Block) GetTxns() []*Tx

func (*Block) GetVersion

func (b *Block) GetVersion() []byte

func (*Block) Hash

func (b *Block) Hash() []byte

func (*Block) Len

func (b *Block) Len() int

func (*Block) SetBits

func (b *Block) SetBits(bi uint32)

func (*Block) SetMerkleRoot

func (b *Block) SetMerkleRoot(merkle []byte)

func (*Block) SetMerkleRootStr

func (b *Block) SetMerkleRootStr(merkle string)

func (*Block) SetMerkleRootStrRev

func (b *Block) SetMerkleRootStrRev(merkle string)

func (*Block) SetNonce

func (b *Block) SetNonce(non uint32)

func (*Block) SetPrevBlock

func (b *Block) SetPrevBlock(prev []byte)

func (*Block) SetPrevBlockStr

func (b *Block) SetPrevBlockStr(prev string)

func (*Block) SetPrevBlockStrRev

func (b *Block) SetPrevBlockStrRev(prev string)

func (*Block) SetTimestamp

func (b *Block) SetTimestamp(time uint32)

func (*Block) SetVersion

func (b *Block) SetVersion(ver uint32)

type BlockHeader

type BlockHeader struct {
	Version    [4]byte
	PrevBlock  [32]byte //char[32]
	MerkleRoot [32]byte //char[32]
	Timestamp  [4]byte
	Bits       [4]byte
	Nonce      [4]byte
	TxnCount   [1]byte
}

TODO: test

func (*BlockHeader) Compile

func (bh *BlockHeader) Compile() []byte

func (*BlockHeader) GetBits

func (bh *BlockHeader) GetBits() []byte

func (*BlockHeader) GetMerkleRoot

func (bh *BlockHeader) GetMerkleRoot() []byte

func (*BlockHeader) GetNonce

func (bh *BlockHeader) GetNonce() []byte

func (*BlockHeader) GetPrevBlock

func (bh *BlockHeader) GetPrevBlock() []byte

func (*BlockHeader) GetTimestamp

func (bh *BlockHeader) GetTimestamp() []byte

func (*BlockHeader) GetTxnCount

func (bh *BlockHeader) GetTxnCount() []byte

func (*BlockHeader) GetVersion

func (bh *BlockHeader) GetVersion() []byte

func (*BlockHeader) Hash

func (bh *BlockHeader) Hash() []byte

func (*BlockHeader) Len

func (bh *BlockHeader) Len() int

func (*BlockHeader) SetBits

func (bh *BlockHeader) SetBits(bi uint32)

func (*BlockHeader) SetMerkleRoot

func (bh *BlockHeader) SetMerkleRoot(merkle []byte)

func (*BlockHeader) SetMerkleRootStr

func (bh *BlockHeader) SetMerkleRootStr(merkle string)

func (*BlockHeader) SetNonce

func (bh *BlockHeader) SetNonce(non uint32)

func (*BlockHeader) SetPrevBlock

func (bh *BlockHeader) SetPrevBlock(prev []byte)

func (*BlockHeader) SetPrevBlockStr

func (bh *BlockHeader) SetPrevBlockStr(prev string)

func (*BlockHeader) SetTimestamp

func (bh *BlockHeader) SetTimestamp(time uint32)

func (*BlockHeader) SetVersion

func (bh *BlockHeader) SetVersion(ver uint32)

type CheckOrder

type CheckOrder struct {
}

TODO: do TODO: figure out? https://en.bitcoin.it/wiki/Protocol_specification#checkorder

type GetBlocks

type GetBlocks struct {
	Version            [4]byte
	StartCount         mymath.VarInt //var_int
	BlockLocatorHashes []Hash
	HashStop           Hash
}

func (*GetBlocks) AddHash

func (gb *GetBlocks) AddHash(newhash Hash)

func (*GetBlocks) Clear

func (gb *GetBlocks) Clear()

func (*GetBlocks) Compile

func (gb *GetBlocks) Compile() []byte

TODO: test

func (*GetBlocks) SetStopHash

func (gb *GetBlocks) SetStopHash(stop Hash)

func (*GetBlocks) SetVersion

func (gb *GetBlocks) SetVersion(newVersion uint32)

type GetData

type GetData Inv

getdata responce to inv

type GetHeaders

type GetHeaders struct {
	StartCount mymath.VarInt //var_int
	HashStart  Hash
	HashStop   Hash
}

func (*GetHeaders) Compile

func (gh *GetHeaders) Compile() []byte

TODO: test

func (*GetHeaders) SetStartCount

func (gh *GetHeaders) SetStartCount(start mymath.VarInt)

func (*GetHeaders) SetStartHash

func (gh *GetHeaders) SetStartHash(start Hash)

func (*GetHeaders) SetStopHash

func (gh *GetHeaders) SetStopHash(stop Hash)

type Hash

type Hash [32]byte

func NewHash

func NewHash(b []byte) Hash

func NewHashFromBig

func NewHashFromBig(hash *big.Int) Hash

func NewHashFromString

func NewHashFromString(hash string) Hash

func (Hash) Len

func (h Hash) Len() int

type Headers

type Headers struct {
	Count   mymath.VarInt
	Headers []*BlockHeader //block_header[]
}

TODO:test

func (*Headers) AddHeader

func (hs *Headers) AddHeader(bh *BlockHeader)

TODO:check if there is any limit on Count

func (*Headers) Clear

func (hs *Headers) Clear()

func (*Headers) Compile

func (hs *Headers) Compile() []byte

type Inv

type Inv struct {
	Count     mymath.VarInt //var_int
	Inventory []*InventoryVector
}

func (*Inv) Clear

func (i *Inv) Clear()

func (*Inv) Compile

func (i *Inv) Compile() []byte

TODO: double check if 36 is really the answer

type InventoryVector

type InventoryVector struct {
	Vectortype uint32
	Hash       [32]byte
}

TODO: test

func (*InventoryVector) Compile

func (iv *InventoryVector) Compile() []byte

func (*InventoryVector) SetHash

func (iv *InventoryVector) SetHash(newhash []byte)

func (*InventoryVector) SetType

func (iv *InventoryVector) SetType(newtype uint32)

type NetworkAddress

type NetworkAddress struct {
	Time     [4]byte
	Services [8]byte
	IP       [16]byte
	Port     [2]byte
}

func (*NetworkAddress) Compile

func (na *NetworkAddress) Compile() []byte

func (*NetworkAddress) CompileForVersion

func (na *NetworkAddress) CompileForVersion() []byte

func (*NetworkAddress) GetHash

func (na *NetworkAddress) GetHash() []byte

TODO: do

func (*NetworkAddress) SetIP

func (na *NetworkAddress) SetIP(IP net.IP)

func (*NetworkAddress) SetPort

func (na *NetworkAddress) SetPort(port uint16)

func (*NetworkAddress) SetServices

func (na *NetworkAddress) SetServices(ser uint64)

func (*NetworkAddress) SetTimestamp

func (na *NetworkAddress) SetTimestamp(setTime uint32)

func (*NetworkAddress) SetTimestampNow

func (na *NetworkAddress) SetTimestampNow(setTime uint32)

type OutPoint

type OutPoint struct {
	Hash  Hash
	Index [4]byte
}

TODO:test

func (*OutPoint) Compile

func (op *OutPoint) Compile() []byte

TODO:test

func (*OutPoint) GetHash

func (op *OutPoint) GetHash() []byte

func (*OutPoint) GetIndex

func (op *OutPoint) GetIndex() []byte

func (*OutPoint) Len

func (op *OutPoint) Len() int

func (*OutPoint) SetHash

func (op *OutPoint) SetHash(newHash Hash)

func (*OutPoint) SetIndex

func (op *OutPoint) SetIndex(ind uint32)

type Reply

type Reply struct {
	Reply [4]byte
}

TODO: test

func (*Reply) Compile

func (r *Reply) Compile() []byte

func (*Reply) Len

func (r *Reply) Len() int

func (*Reply) SetReply

func (r *Reply) SetReply(rep uint32)

type SubmitOrder

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

TODO: do https://en.bitcoin.it/wiki/Protocol_specification#submitorder

type Tx

type Tx struct {
	Version    [4]byte
	TxInCount  mymath.VarInt
	TxIn       []*TxIn //[]TxIn
	TxOutCount mymath.VarInt
	TxOut      []*TxOut //[]TxOut
	LockTime   [4]byte
}

TODO: test

func DecodeMultipleTxs

func DecodeMultipleTxs(txs []byte, count int) ([]*Tx, []byte)

TODO: test

func DecodeTx

func DecodeTx(tx []byte) (*Tx, []byte)

TODO: test

func (*Tx) AddIn

func (t *Tx) AddIn(txin *TxIn)

func (*Tx) AddOut

func (t *Tx) AddOut(txout *TxOut)

func (*Tx) ClearIn

func (t *Tx) ClearIn()

func (*Tx) ClearOut

func (t *Tx) ClearOut()

func (*Tx) Compile

func (t *Tx) Compile() []byte

TODO:test

func (*Tx) GetLockTime

func (t *Tx) GetLockTime() []byte

func (*Tx) GetTxIn

func (t *Tx) GetTxIn() []*TxIn

func (*Tx) GetTxInCount

func (t *Tx) GetTxInCount() mymath.VarInt

func (*Tx) GetTxOut

func (t *Tx) GetTxOut() []*TxOut

func (*Tx) GetTxOutCount

func (t *Tx) GetTxOutCount() mymath.VarInt

func (*Tx) GetVersion

func (t *Tx) GetVersion() []byte

func (*Tx) Hash

func (t *Tx) Hash() []byte

TODO: test TODO: double check if rev or not

func (*Tx) Len

func (t *Tx) Len() int

TODO:test

func (*Tx) SetLockTime

func (t *Tx) SetLockTime(time uint32)

func (*Tx) SetVersion

func (t *Tx) SetVersion(ver uint32)

type TxIn

type TxIn struct {
	PreviousOutput  OutPoint
	ScriptLength    mymath.VarInt
	SignatureScript []byte //uchar[]
	Sequence        [4]byte
}

TODO:test

func DecodeMultipleTxIns

func DecodeMultipleTxIns(b []byte, count int) ([]*TxIn, []byte)

TODO: test

func DecodeTxIn

func DecodeTxIn(b []byte) (*TxIn, []byte)

TODO: test

func (*TxIn) Compile

func (ti *TxIn) Compile() []byte

TODO:test

func (*TxIn) GetPreviousOutput

func (ti *TxIn) GetPreviousOutput() OutPoint

func (*TxIn) GetScriptLength

func (ti *TxIn) GetScriptLength() mymath.VarInt

func (*TxIn) GetSequence

func (ti *TxIn) GetSequence() []byte

func (*TxIn) GetSignatureScript

func (ti *TxIn) GetSignatureScript() []byte

func (*TxIn) Len

func (ti *TxIn) Len() int

TODO:test

func (*TxIn) SetOutPoint

func (ti *TxIn) SetOutPoint(out OutPoint)

func (*TxIn) SetSequence

func (ti *TxIn) SetSequence(seq uint32)

func (*TxIn) SetSignature

func (ti *TxIn) SetSignature(sig []byte)

type TxOut

type TxOut struct {
	Value          [8]byte
	PkScriptLength mymath.VarInt
	PkScript       []byte //uchar[]
}

TODO:test

func DecodeMultipleTxOuts

func DecodeMultipleTxOuts(b []byte, count int) ([]*TxOut, []byte)

TODO: test

func DecodeTxOut

func DecodeTxOut(b []byte) (*TxOut, []byte)

TODO: test

func (*TxOut) Compile

func (to *TxOut) Compile() []byte

TODO:test

func (*TxOut) GetPkScript

func (to *TxOut) GetPkScript() []byte

func (*TxOut) GetPkScriptLength

func (to *TxOut) GetPkScriptLength() mymath.VarInt

func (*TxOut) GetValue

func (to *TxOut) GetValue() []byte

func (*TxOut) Len

func (to *TxOut) Len() int

TODO:test

func (*TxOut) SetScript

func (to *TxOut) SetScript(script []byte)

func (*TxOut) SetScriptStr

func (to *TxOut) SetScriptStr(script string, opcode byte)

func (*TxOut) SetValue

func (to *TxOut) SetValue(val uint64)

type VersionMessage

type VersionMessage struct {
	Version       [4]byte
	Services      [8]byte
	Timestamp     [8]byte
	AddrYou       [26]byte
	AddrMe        [26]byte
	Nonce         [8]byte
	SubVersionNum []byte
	StartHeight   [4]byte
}

TODO: double checks, but it's probably OK

func (*VersionMessage) Compile

func (vm *VersionMessage) Compile() []byte

func (*VersionMessage) SetAddrMe

func (vm *VersionMessage) SetAddrMe(ip net.IP, ser uint64, port uint16)

func (*VersionMessage) SetAddrYou

func (vm *VersionMessage) SetAddrYou(ip net.IP, ser uint64, port uint16)

func (*VersionMessage) SetNonce

func (vm *VersionMessage) SetNonce(n uint64)

func (*VersionMessage) SetRandomNonce

func (vm *VersionMessage) SetRandomNonce()

func (*VersionMessage) SetServices

func (vm *VersionMessage) SetServices(ser uint64)

func (*VersionMessage) SetStartHeight

func (vm *VersionMessage) SetStartHeight(block uint32)

func (*VersionMessage) SetSubVersionNull

func (vm *VersionMessage) SetSubVersionNull()

func (*VersionMessage) SetTimestamp

func (vm *VersionMessage) SetTimestamp(setTime uint64)

func (*VersionMessage) SetTimestampNow

func (vm *VersionMessage) SetTimestampNow()

func (*VersionMessage) SetVersion

func (vm *VersionMessage) SetVersion(ver uint32)

Jump to

Keyboard shortcuts

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