Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the Neo Domain Model #1866

Open
devhawk opened this issue Aug 21, 2020 · 1 comment
Open

Unify the Neo Domain Model #1866

devhawk opened this issue Aug 21, 2020 · 1 comment
Labels
Discussion Initial issue state - proposed but not yet accepted

Comments

@devhawk
Copy link
Contributor

devhawk commented Aug 21, 2020

Objective

Improve the developer experience by having compatible source definition of common domain
model types such as Block and Transaction across RpcClient, Neo node plugins and the Smart
Contract Framework.

Problem

Core domain types like Block and Transaction have a different definition in the Smart
Contract framework and Neo core. This makes it harder for developers to learn and use
the Neo platform. It also makes it harder to move code between dApp clients and smart
contracts.

Examples:

  • Block.PrevHash field is a byte[] in the Smart Contract Framework and a UInt256 in Neo
  • To retrieve a Transaction from a block in Neo, you use the Block.Transaction array. To retrieve a
    Transaction from a block in Smart Contract Framework, you call Blockchain.GetTransactionFromBlock
  • Neo supports a variety of contract parameter types that have no represenation in smart contracts
    such as Hash160/256, Public Key and Signature

Proposals

  • Create a new namespace Neo.Models.
  • Move domain models from their current namespaces to Neo.Models
    • For Neo core, this means moving Block, BlockBase, Header and Transaction from Neo.Network.P2P.Payloads to Neo.Models.
    • For Contract Framework, this means moving Block and Transaction from Neo.SmartContract.Framework.Services.Neo
  • Add UInt160, UInt256 and ECPoint types to Contract Framework in namespaces that match locations form Neo core
    • These fundamental types will continue to be represented in the VM as byte arrays. The goal of this change is to provide familiarity and basic type safety
    • Functional parity between neo core and contract framework for these types is NOT A REQUIREMENT.
    • These types need explicit byte array cast operator for use as storage keys and values. Since these types are stored as byte arrays in the VM, the cast operator is a no-op, but there to reinforce to the developer the correct usage of these types
  • Update contract framework Block and Transaction to use UInt160/256 for properties where appropriate to match neo core
    • Example: Hash field of block and transaction should be UInt256 not byte[]
  • Update contract framework Block to expose Transactions read only indexable collection instead of using TransactionCount field + Blockchain.GetTransactionForBlock method
  • Update contract framework services to use new fundamental types where appropriate instead of byte arrays. Introduce overloads where needed
    • Example: Runtime.CheckWitness should have two overloads, taking UInt160 and ECPoint
  • Simplify the namespace of service types in the contract framework.
    • Neo.SmartContract.Framework.Services.Neo -> Neo.Contract.Services
  • Move Smart Contract types used to control the compilation process such as SyscallAttribute and IApiInterface out of the root contract framework namespace and into a new Neo.Contract.Metadata namespace
  • Update NEON compiler + neo core to support contract framework changes as appropriate
@devhawk devhawk added the Discussion Initial issue state - proposed but not yet accepted label Aug 21, 2020
@devhawk
Copy link
Contributor Author

devhawk commented Aug 27, 2020

An example of the kind of bug that happens because we don't have a UInt160 type in the Smart Contract Framework: neo-project/neo-devpack-dotnet#342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Initial issue state - proposed but not yet accepted
Projects
None yet
Development

No branches or pull requests

1 participant