GithubHelp home page GithubHelp logo

graphstore's Introduction

WebWallet Graphstore

Transaction clearing microservice for the WebWallet API.

Contents

  • Graph Database
  • Data Modeling
  • Query Design

Graph Database

Neo4j

  • Cypher

Data Modeling

Nodes

Labels: IOU, Address, Currency, Transaction, Outputs.

  • IOU
  • Address
  • Currency
  • Transaction
    A transaction is a document, not an operation. Inserting a Transaction node is not equivalent to executing a transaction, which involves creating other nodes and relationships as well.
    • Outputs

Relationships

Types: Funds, Spends, Points.

  • Clearing
    • IOUs
    • Outputs
  • Indexing
    • Outputs

Constraints

Nodes with Address labels must satisfy the id property uniqueness constraint. Since Transaction nodes will be retrieved through traversals starting at Address nodes using their Outputs node (manual index), no constraint is imposed on Transaction node IDs in order to prevent a potentially large index from being created automatically by the database.

CREATE CONSTRAINT ON (address:Address) ASSERT address.id IS UNIQUE

Since uniqueness contraints cannot be created on relationships, CREATE UNIQUE must be used in combination with previous checks in order to manually enforce unique relationships on nodes.

...
WHERE NOT (txo)<-[:Spends {id:0}]-()
CREATE UNIQUE (txo)<-[s:Spends {id: 0}]-(txn)
...

Relationships with Spends labels should satisfy the id property existence constraint [enterprise edition feature]. Since Transaction documents contain outputs that can be referenced by subsequent transactions for clearing purposes, every Transaction that Spends another Transaction must specify which output it is referencing/spending.

CREATE CONSTRAINT ON ()-[output:Spends]-() ASSERT exists(output.id)

Query Design

Clearing

  • Output Spending
MATCH (txo:Transaction)
WHERE txo.id = {transactionId}
SET txo.lock = true
WITH txo
WHERE NOT (txo)<-[:Spends {id:{outputId}}]-()
CREATE UNIQUE (txo)<-[:Spends {id: {outputId}}]-(txn:Transaction)
REMOVE txo.lock
RETURN txo, txn

graphstore's People

Contributors

boolpath avatar

Watchers

James Cloos avatar  avatar

Forkers

hashtagcoin

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.