Giter Club home page Giter Club logo

corda-foreign-exchange-example's Introduction

Corda

Corda Foreign Exchange Example

Basic information

Currently based upon Corda version 1.0

This example illustrates how a foreign currency exchange could be implemented using Corda.

While the functionality is not extremely complicated, the structure shows how to decompose behaviour into different Corda nodes, and how to use Oracles as part of Flows.

It also demonstrate how to integrate CORDA into a web application.

This repository is split into seven modules: * The shared module holds general types that all parties (buyers, sellers and exchange rate providers) need to use * The buyer module holds the flows and plugin run by the buyer of foreign exchange * The seller module holds the flow and plugin run by the seller of foreign exchange * The rate-provider module holds the flows, service and plugin run by the exchange rate provider * The buyer-api module holds the interface the seller of foreign exchange should use as an initiating flow when writing a flow to speak to the buyer * The rate-provider_api module holds the interfaces the buyer and seller of foreign exchange should use as initiating flows when querying the oracle for an exchange rate or a transaction signature * The buyer-app module holds two web server implementations: Ktor(buyer_app:web-server-ktor) and Spring-Boot(buyer_app:web-server-spring-boot). These implementations are identical in behaviour and only there to demonstrate that the client can be arbitrarily chosen The purpose of a modular setup is to avoid having parties knowing the implementation code of other peers.

The Spring Boot and Ktor webserver implementations are identical in behaviour and only there to demonstrate that the client can be arbitrarily chosen.

How to run this example

  • From terminal inside project root, run ./gradlew deployNodes and wait for it to finish.
  • From terminal inside project root, run ./build/nodes/runnodes and wait for it to finish.
  • Run/Debug Starter.kt inside project 'buyer-app:web-server-ktor' or 'buyer-app:web-server-spring-boot' from Intellij.

What's available

As for the buyer app, available driving endpoints on localhost:8080 are:

  • GET /cash -> returns a map currency to available cash balance. Initially empty.
  • GET /exchangeRate?from=&to= e.g., /exchangeRate?from=GBP&to=USD -> returns the exchange rate between specified currencies, or Not Found. Response body is e.g, {"rate": 1.36, "from": "GBP", "to": "USD"}.
  • POST /cash e.g., payload {"value": 1000.0, "currency": "GBP"} -> issues available cash to the buyer node.
  • POST /purchases e.g., payload {"amount": {"value": 100.0, "currency": "USD"}, "currency": "GBP"} -> buys given amount ($10) from seller node by accepting exchange rate (GBP to USD) from rate-provider.

Example calls

  1. GET /cash -> empty (200 OK).
  2. POST /cash with payload {"value": 1000.0, "currency": "GBP"} -> no response body (201 Created).
  3. GET /cash -> {"GBP":1000.0} (200 OK).
  4. GET /exchangeRate?from=GBP&to=USD -> {"rate":1.36,"from":"GBP","to":"USD"} (200 OK).
  5. POST /purchases with payload {"amount": {"value": 100.0, "currency": "USD"}, "currency": "GBP"} -> no response body (201 Created).
  6. GET /cash -> {"USD":100.0,"GBP":864.0} (200 OK).
  7. As expected, the dollars have been bought and the remaining pounds £864 = £1000 - 1.36 (£/$) * $100.

Additional remarks

  • All currency codes are available to generate cash.
  • Only USD, EUR and GBP are available as input/output for currency exchange.

corda-foreign-exchange-example's People

Contributors

sollecitom avatar kevin-dervishi avatar

Watchers

James Cloos avatar Purushothaman Kesavan avatar

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.