neo-go/pkg/wire
decentralisedkev 30e5aa8f48
Add Chain saving functionality to Database (#206)
* [database]

- Add Prefix method to interface
- Convert leveldb error to `database error`
- Be explicit with prefixedKey in `Table` as slices can be pointers

* [protocol]
- Add stringer method to protocol

* [Chaindb]

- Added saveBlock() which will allow us to save a block into the
database. The block is broken up into transactions and Headers. The
headers are saved as is. The transactions are saved as is, then the
utxos in the transactions are collected to make the utxo db.

- Verification for blocks and transactions will reside in the same
package. Note that the save methods are all unexported, while the Get
methods are exported. Making it so that any can call a get method, but
only code in this package may save to the database. The other code which
will reside in this package will be code verification logic.

* [chaindb]

- Added saveHeader function which saveHeaders  uses

- Update the latest header, each time we save a header instead of after a batch. This is so that we can call saveHeader without saveHeaders. This functionality can be rolled back if the performance of updating the header after a batch is significant

- small refactor in test code
2019-03-23 16:57:05 +00:00
..
command Fix lint errors (#182) 2019-03-17 18:26:35 +00:00
payload 1) Fixed String method in Uint256 (#208) 2019-03-23 16:52:36 +00:00
protocol Add Chain saving functionality to Database (#206) 2019-03-23 16:57:05 +00:00
util 1) Fixed String method in Uint256 (#208) 2019-03-23 16:52:36 +00:00
base.go Fix lint errors (#182) 2019-03-17 18:26:35 +00:00
message.go Fix lint errors (#182) 2019-03-17 18:26:35 +00:00
message_test.go Initial commit 2019-02-25 22:44:14 +00:00
Readme.md Initial commit 2019-02-25 22:44:14 +00:00

Package - Wire

The neo wire package will implement the network protocol displayed here: http://docs.neo.org/en-us/network/network-protocol.html

This package will act as a standalone package.

Responsibility

This package will solely be responsible for Encoding and decoding a Message. It will return a Messager interface, which means that the caller of the package will need to type assert it to the appropriate type.

Usage

Write Message

expectedIP := "127.0.0.1"
expectedPort := 8333
tcpAddrMe := &net.TCPAddr{IP: net.ParseIP(expectedIP), Port: expectedPort}
message, err := NewVersionMessage(tcpAddrMe, 0, true, defaultVersion)

conn := new(bytes.Buffer)
if err := WriteMessage(con, Production, message); err != nil {
	// handle Error
}

Read Message

readmsg, err := ReadMessage(conn, Production)

if err != nil {
	// Log error
}
version := readmsg.(*VersionMessage)

RoadMap

These below commands are left to implement.

[ x ] CMDVersion (Tests added)
[ x ] CMDVerack (Tests Added)
[ x ] CMDGetAddr(Tests Added)
[ x ] CMDAddr (Tests Added)
[ x ] CMDGetHeaders (Tests Added)
[ x ] CMDHeaders (Tests Added)
[ x ] CMDGetBlocks (Tests Added)
[ x ] CMDInv (Tests Added)
[ x ] CMDGetData (Tests Added)
[ x ] CMDBlock (Tests Added)
[ x ] CMDTX // Each tx implments the messager interface
[   ] CMDConsensus

Notes

Please not that this package will do sanity checks on the fields, however it will not verify if any of the items are valid for the current state of the system. Please see Responbilities.

The difference between Encode/Decode and EncodePayload/DecodePayload, is the parameter type. In most cases, Encode/Decode is just a convenience method.

Contributors

When modifying this package, please ensure that it does not depend on any other package and that it conforms to the Single Responsibility Principle. If you see somewhere in the current implementation that does not do this, then please tell me.