Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Latest commit

 

History

History
194 lines (130 loc) · 5.04 KB

README.md

File metadata and controls

194 lines (130 loc) · 5.04 KB

sandbox

C3 Go

Go implementation of the C3 protocol

License CircleCI Coverage Status Go Report Card GoDoc Automated Release Notes by gren stability-experimental

Install

Requirements

Docker config

Set up a localhost proxy route to 123.123.123.123

$ sudo ifconfig $(ifconfig | grep LOOPBACK | awk '{print $1}' | sed -E 's/[^a-zA-Z0-9]+//g') 123.123.123.123/24

Then configure daemon.json to include the private registry as insecured (because it's localhost).

{
  "insecure-registries" : [
    "123.123.123.123:5000"
  ]
}
  • Linux
    • /etc/docker/daemon.json
  • macOS
    • ~/.docker/daemon.json

Restart the docker daemon after configuring daemon.json

Install c3-go

Install using go get (must have Go installed).

$ go get -u github.com/c3systems/c3

Hello world tutorial

Warning: Tutorial is not the most intuitive. Please bear with me as we're still in the proof-of-concept stage.

  1. Generate new private keys
$ c3-go generate key -o priv.pem
$ c3-go generate key -o priv2.pem
  1. Run the C3 node
$ c3-go node start --pem=priv.pem --uri /ip4/0.0.0.0/tcp/3330 --data-dir ~/.c3

INFO[0002] [node] 0: /ip4/127.0.0.1/tcp/3330/ipfs/QmNRR7uLZ2bZXjjQqEY5fcm5BXubBEne3bkq6pYwg1QR18
  source="start.go:152:node.Start"
  1. In another terminal, clone and build the hello-world dapp
$ git clone https://github.com/c3systems/c3-sdk-go-example-hello-world.git hello-world

$ (cd hello-world && docker build .)
  1. Push the image to IPFS
$ c3-go push $(docker images -q | grep -m1 "")

[registry] uploaded to /ipfs/QmWJF5MYtnjb76P1CXQsn8MHpT26tjdBcs6CzKfR7zjRBm
  source="registry.go:101:registry.(*Registry).PushImage"
  1. Deploy the image to the local C3 testnet (update image and peer to your own values)
$ c3-go deploy --priv priv2.pem --genesis '' --image QmWJF5MYtnjb76P1CXQsn8MHpT26tjdBcs6CzKfR7zjRBm --peer "/ip4/127.0.0.1/tcp/3330/ipfs/QmZQ3cJMMjA7HUyEvsMXmN73LZ7fKsrQUmyKwsxrpecb7Z"
  • The private key is the second key derived from step 1.
  • The peer multihash was derived from step 2.
  • The image hash was derived from step 4.
  1. Invoke a method on the dApp (update image and peer to your own values from the previous step)
$ go run main.go invokeMethod --priv priv2.pem --payload '["setItem", "foo", "bar"]' --image QmWJF5MYtnjb76P1CXQsn8MHpT26tjdBcs6CzKfR7zjRBm --peer "/ip4/127.0.0.1/tcp/3330/ipfs/QmZQ3cJMMjA7HUyEvsMXmN73LZ7fKsrQUmyKwsxrpecb7Z"
  • In this example we're invoking the setItem method which accepts two arguments; the values are foo and bar. The example dApp code is found here.

  • The private key is the second key derived from step 1.

  • The peer multihash was derived from step 2.

  • The image hash was derived from step 4.

  1. That's it; you've just deployed a dApp and invoked a method by broadcasting a transaction.

CLI commands

Show help for C3

$ c3-go help

Push image to IPFS

$ c3-go push {imageID}

Pull image from IPFS

$ c3-go pull {ipfsHash}

Run a node

$ c3-go node start [options]

Generate a private key

$ c3-go generate key

Encode data

$ c3-go encode [options]

Deploy dApp

$ c3-go deploy [options]

Invoke dApp method

$ c3-go invokeMethod [options]

Sign a transaction

$ c3-go sign --priv=priv.pem --image={imageID} --payload='["someMethod", "foo", "bar"]'

Test

$ make test

Tests require docker daemon and IPFS daemon to be running.

Development

Install new dependencies to vendor/ (will take a couple of minutes)

$ make deps

License

GNU AGPL 3.0