Code Monkey home page Code Monkey logo

neo-blockchaintoolkit-library's Introduction

Neo Blockchain Toolkit Persistence Library

Build Status

This repo projects for code shared between managed projects in the Neo Blockchain Toolkit. In particular, these libraries are used in Neo-Express and the Neo Smart Contract Debugger for VS Code.

Continutious Integration build packages are available via Azure Artifacts.

Models

This library contains classes for reading and writing .neo-express files and NEP-19 compatible debug information

Contract Parameter Parsing

This library contains code to parse Neo Express contract invoke files as specified in NDX-DN12. This includes custom handling of JSON native types (boolean, integer, null, array) as well as custom handling of JSON strings for encoding addresses with @ prefix, hashes with # prefix and hex strings with 0x prefix.

Persistence

This library contains two Neo.Persistence.IStore implementations:

  • RocksDbStore: This implementation stores blockchain information in a RocksDb. It is similar to the RocksDbStore implementation in neo-modules, but is optimized for developer scenarios, including live checkpoint support.

  • MemoryTrackingStore: This implementation sits on top of any Neo.Persistence.IReadOnlyStore implementation and stores all changes in memory. This enables test/debug runs to use live data without persisting further changes.

  • PersistentTrackingStore: This implementation sits on top of any Neo.Persistence.IReadOnlyStore implementation and stores all changes on disk.

  • CheckpointStore: This implementation of Neo.Persistence.IReadOnlyStore pulls data from a Neo Express checkpoint. Combined with a tracking store, this enables test/debug runs to use live data without persisting further changes.

  • StateServiceStore: This implementation of Neo.Persistence.IReadOnlyStore sits on top of a StateService node running with FullState: true. Combined with a tracking store, this enables code to use live data from a public Neo blockchain network such as MainNet or TestNet.

Trace Models

This library contains the model classes that read/write Time Travel Debugging (TTD) traces. TTD traces are encoded using MessagePack. These model classes use the MessagePack managed library. In addition to the trace model classes, this library includes message pack formatters for Neo types that are serialized in TTD traces as well as a MessagePack resolver.

Application Engines

This library contains two Neo.SmartContract.ApplicationEngine subclasses:

  • TestApplicationEngine: This implementation is used across test scenarios. It supports overriding the CheckWitness service and collecting code coverage information
  • TraceApplicationEngine: This implementation writes trace information to a provided ITraceDebugSink. The Trace Model classes (described above) include an implementation of ITraceDebugSink that writes trace messages to a file in MessagePack format.

neo-blockchaintoolkit-library's People

Contributors

ashuaidehao avatar devhawk avatar johndevadoss avatar merl111 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

neo-blockchaintoolkit-library's Issues

SUGGESTED FEATURE: Add ToString() method to UInt160 type

Currently, to convert a UInt160 value to a string you can use with facilities like Runtime.Log(), you have to do this bit of trickery (thank you @hal0x2328):

StdLib.Base58CheckEncode("5" + (ByteString) value))

Where value is a UInt1601 value. I suggest making a ToString()method for theUInt160` type so that it is easily discoverable by NEO developers.

Fix ContractParameterParser for args data types

Fix ContractParameterParser see neo-project/neo-express#285

from the looks of it

if (value[0] == '@')
{
var substring = value[1..];
if (tryGetAccount != null && tryGetAccount(substring, out var account))
{
return new ContractParameter(ContractParameterType.Hash160) { Value = account };
}
if (TryParseAddress(substring, addressVersion, out var address))
{
return new ContractParameter(ContractParameterType.Hash160) { Value = address };
}
}
else if (value[0] == '#')
{
var substring = value[1..];
if (UInt160.TryParse(substring, out var uint160))
{
return new ContractParameter(ContractParameterType.Hash160) { Value = uint160 };
}
if (UInt256.TryParse(substring, out var uint256))
{
return new ContractParameter(ContractParameterType.Hash256) { Value = uint256 };
}
if (TryLoadScriptHash(substring, out var scriptHash))
{
return new ContractParameter(ContractParameterType.Hash160) { Value = scriptHash };
}
}

only is getting string value or get it as json object

maybe update documentation is key here?

Consider using tooling to enforce consistent coding style and best practices

Back when i last developed in C# as part of a team (admittedly a long time ago now) there was tool called StyleCop, and it was pretty common to enable it and enforce the default rules regardless of opinions of individual team members (consistency over personal preference). It seems like StyleCop is now replaced by Roslyn Analyzers (which I cannot claim to have any experience with).

i think the main issues that old-school StyleCop would have found in the neo-express code base are catching Exception and lack of { and } on one line conditionals.

This issue is intended to encourage a discussion that leaves us confident that we're following current-day norms and best practices for C# development - please don't see it as me trying to force my personal preferences on the code base :)

StateServiceStore throws when retrieving missing key from ledger storage

StateService does not track Ledger contract items (blocks and transactions) since they are already immutable.
StateServiceStore translates requests for such K/V pairs into a call to getstorage. If the storage key doesn't
exist, RpcServer returns an error with code -100. StateServiceStore fails to catch this error.

Invoke file updates

I've got a branch where I'm working on updates to invoke file parsing. As part of this work, should we consider updates to the .neo-invoke file format?

Today, the ContractParameterParser class parses one or more objects that map to ScriptBuilder.EmitDynamicCall. The object properties map to the EmitDynamicCall parameters

  • contract property is parsed into the UInt160 contract script hash
  • operation property is a string that indicates the operation to invoke
  • args property is an optional array of JSON values that are parsed into a ContractParameters

Other information that could be added to the invoke file

  • CallFlags: If not provided, EmitDynamicCall defaults to CallFlags.All. Should we add a call-flags field to the dynamic call JSON object?
  • Signers: Today, NeoExpress generates a single signer for an invocation via the Account argument and WitnessScope option. However, this is only a fraction of transaction signing flexibility
    • a transaction can have multiple signers
    • a signer must have an account hash and WitnessScope, but also supports allowed contracts, allowed groups and witness rules. Today, express has no mechanism to allow the developer to specify this additional signer information.
  • TransactionAttribute: Transactions can have zero or more attributes. Today, there are only two defined attributes: HighPriority and OracleResponse. Express already has an oracle response command, so there shouldn't be any need to specify this directly. HighPriority is used for ordering transactions in the mem pool, so is conceivably interesting. However, HighPriority transactions MUST be signed by the NEO committee, so they are of limited use by rank-and-file developers.
  • Additional GAS fees: transactions in the mempool are ordered by FeePerByte and then NetworkFee, thus there are scenarios for increasing the network fee paid for preferential mempool ordering. However, since neo express runs locally, there aren't typically a large number of transactions in the mempool, so it's not clear how much use this would be.
    • Note, express contract invoke has an --additional-gas argument, but that adds to SystemFee not NetworkFee. This is actually a hold over from Neo N3 beta timeframe where there were bugs in the system fee calculation engine. This argument should probably be deprecated

IMO, we should consider providing a mechanism to encode complete singer information in JSON for use in invoke file scenarios. I'm actually thinking this should be a separate file (.neo-signers maybe?). The current invoke file mirrors invocation script generation so adding signer information would break some backwards compatibility. Additionally, a separate file would enable use in contract run command as well as contract invoke.

We should also add CallFlags property to the dynamic call object. It's not used often, but it's also fairly easy to add. Unlike other properties like account and contract, parsing a CallFlags string -> enum value is straightforward and requires no outside information

Support invalid document index in sequence points

nccs RC2 has a known issue where it emits negative numbers as an invalid document index for sequence points in certain scenarios.

While it has been fixed post RC2, this leads to a poor developer experience for RC2. If we update the debug info parser + debugger to ignore these invalid values, we can have a better developer experience for the hackathon

StateServiceStore throws when unknown contract id passed to TryGet or Seek

StateServiceStore has a map of internal contract ID (int32) to contract hash (UInt160) generated from the contracts that were deployed at the point where the state service store branch was created. If a contract is deployed to a chain backed by StateServiceStore, TryGet and Seek methods throw an exception because the newly generated contract ID is not in the contract map.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.