GithubHelp home page GithubHelp logo

nunofernandes-plight / pact Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kadena-io/pact

0.0 2.0 0.0 3.41 MB

The Pact Smart Contract Language

Home Page: http://kadena.io/pact

License: BSD 3-Clause "New" or "Revised" License

Haskell 97.00% Nix 0.55% HTML 0.24% JavaScript 0.88% Shell 0.06% C 1.27%

pact's Introduction

The Pact Programming Language

Build Status

This is the source code repository for Pact, a language for developing smart contracts to run on a fast deterministic blockchain.

References

Pact Homepage

Pact Reference Docs

Pact Whitepaper

Quick Start: Browser

The easiest way to try Pact is in the browser.

Quick Start: Atom

To start writing smart contracts, the best way to go is to use the Atom editor and install language-pact using the package manager.

Installing Pact with homebrew (OSX only)

You'll then need to install the Pact interpreter/REPL. On Mac, the easiest way is with homebrew.

brew install kadena-io/pact/pact

Installing Pact with Binary Distributions

Prebuilt binaries are available, or see building below.

Once you have downloaded the binary, put it somewhere in your PATH.

Verifying Install

Test by issuing pact in a terminal. Try out some commands:

$ pact
pact> (+ 1 2)
3
pact> (+ "hello, " "world")
"hello, world"

There are examples in this source repository of working smart contracts which you can load into Atom to get started.

Quick Start: Pact REST API Server

Pact now features a full REST API HTTP server and SQLite database implementation, making blockchain application development painless and easy. The Pact server simulates a single-node blockchain environment, with the same API supported by the Kadena ScalableBFT blockchain.

To start the server, issue pact --serve CONFIG or pact -s CONFIG, where CONFIG is a valid config.yaml.

REST API Docs

The REST API is documented at http://pact-language.readthedocs.io/en/latest/pact-reference.html#rest-api.

Related Projects

Hosting static files.

The HTTP server will host any static files it finds in its working directory.

Config file format

The pact dev server (pact-serve) requires a configuration Yaml file (e.g. server.conf) to operate. The documentation for it is:

โžœ  pact git:(feat/dev-server) pact --serve --help
Config file is YAML format with the following properties:
port       - HTTP server port
persistDir - Directory for database files.
             If ommitted, runs in-memory only.
logDir     - Directory for HTTP logs
pragmas    - SQLite pragmas to use with persistence DBs
verbose    - [True|False] Provide extra logging information

Replay from disk.

When running pact-serve with persistence enabled, the server automatically replays from the database commands.sqlite in the persist dir. To prevent replay, simply delete this file before starting the server.

Building

Building Pact used to require a working Haskell Stack install . After which, building is as simple as 'stack build'.

To install for use with Atom and the command line, issue 'stack install' and then either add $HOME/.local/bin to your path, or symlink $HOME/.local/bin/pact somewhere in your PATH.

NOTE: We are currently transitioning to Nix build infrastructure. Stack builds still work right now, but you should start transitioning to Nix using the instructions below.

Building with Nix / NixOS

  1. Go to https://nixos.org/nix/, click "Get Nix", follow the instructions to install the Nix package manager.
  2. Edit $NIX_CONF_DIR/nix.conf.
    • Linux default: /etc/nix/nix.conf
  3. Set the substituters and trusted-public-keys lines as follows:
substituters = https://pact.cachix.org https://nixcache.reflex-frp.org https://cache.nixos.org/

trusted-public-keys = pact.cachix.org-1:cg1bsryGrHnQzqEp52NcHq4mBBL+R25XbR2Q/I/vQ8Y= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

NOTE: In older versions of Nix, instead of substituters and trusted-public-keys, use binary-caches and binary-cache-public-keys respectively.

  1. If running Nix in multi-user mode (i.e. with a daemon), restart the Nix daemon.

On Mac:

sudo launchctl stop org.nixos.nix-daemon
sudo launchctl start org.nixos.nix-daemon

On Linux:

sudo systemctl restart nix-daemon.service
  1. Run nix-build from the project root.

Incremental Builds

Building with nix-build does a full rebuild every time, which is usually not what you want when developing. To do incremental builds, you need to enter a nix shell. To do that use the following command:

$ nix-shell -A shells.ghc

This puts you in a shell that has all the necessary dependencies installed. Once inside this shell you can build as normal with cabal using cabal build or cabal new-build.

You can also build with stack inside this shell as follows:

$ stack --stack-yaml stack-nix.yaml build

Hoogle Documentation

Nix has out-of-the-box Hoogle integration. It allows you to run a local Hoogle server with docs for all of the project dependencies. This is really nice for two reasons:

  1. You know you're getting correct docs for the exact versions of the packages you are depending on.

  2. You don't have to have an internet connection to access them.

To start the hoogle server, run this command from the project root directory.

nix-shell -A shells.ghc --run 'hoogle server --local'

This runs hoogle locally on port 8080. Running it this way, however, does not include haddocks for the pact (or whatever tho local project is). It only includes docs for the dependencies. To fix this, use the following command instead:

nix-shell -p 'with import ./. {}; ghc.ghcWithHoogle (p: [p.pact])' --run 'hoogle server --local'

To use the above command for other projects that use the .project function replace [p.pact] with a list of all the locally defined projects to include. For example: [p.backend p.common p.frontend] for a project that has those three separate local packages.

License

This code is distributed under the terms of the BSD3 license. See LICENSE for details.

pact's People

Contributors

andongli avatar bts avatar buckie avatar emilypi avatar fosskers avatar jimmyhmiller avatar joelburget avatar konr avatar larskuhtz avatar lindaortega avatar mightybyte avatar vaibhavsagar avatar

Watchers

 avatar  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.