Skip to content

Commit

Permalink
processing general ledger transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravitt committed Mar 28, 2020
1 parent 6f5f20e commit 3dbffc7
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ package-lock.json
ipld
Dockerfile
demo.txt

*.dat
9 changes: 4 additions & 5 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import (
// MakeGet ...
func MakeGet() *cobra.Command {
var command = &cobra.Command{
Use: "get",
Short: "Get chappe artifacts",
Long: `Retrieve and optionally decrypt a specific item from the data store`,
Example: ` chappe get
chappe get --cid Qmah6HuF5kw1HF9yNfTxxoWBjCRYddestuMYn7RFF4RHnS`,
Use: "get",
Short: "Get chappe artifacts",
Long: `Retrieve and optionally decrypt a specific item from the data store`,
Example: ` chappe get --cid Qmah6HuF5kw1HF9yNfTxxoWBjCRYddestuMYn7RFF4RHnS`,
SilenceUsage: false,
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (

"github.com/eosio-enterprise/chappe/internal/encryption"
"github.com/eosio-enterprise/chappe/pkg"
"github.com/fatih/color"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// var c = cache.New(time.Hour)

// MakePublish ...
func MakePublish() *cobra.Command {
var command = &cobra.Command{
Expand All @@ -41,12 +40,13 @@ func MakePublish() *cobra.Command {
}

for {
privatePayload := pkg.GetFakePrivatePayload()
privatePayload := pkg.GetLedgerPayload()
msg := pkg.NewMessage()
msg.Payload["BlockchainMemo"] = []byte(readableMemo)

payload, _ := json.MarshalIndent(privatePayload, "", " ")
log.Println("Publishing: \n", string(payload))
color.Green("Publishing:")
color.Green(string(payload))

if encryptFlag {
aesKey := encryption.NewAesEncryptionKey()
Expand Down
13 changes: 4 additions & 9 deletions cmd/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,27 @@ import (

"github.com/eosio-enterprise/chappe/pkg"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// MakeSubscribe ...
func MakeSubscribe() *cobra.Command {
var command = &cobra.Command{
Use: "subscribe",
Short: "Subscribe to a channel",
Example: ` chappe subscribe --channel-name MyChannel`,
Example: ` chappe subscribe --channel-name MyChannel --send-receipts --ledgerFile my_ledger_file.dat`,
SilenceUsage: false,
}

var channelName string
var channelName, ledgerFile string
var sendReceipts bool
command.Flags().StringVarP(&channelName, "channel-name", "n", "", "channel name")
command.Flags().BoolVarP(&sendReceipts, "send-receipts", "r", false, "send device-specific receipts back to hub")
command.Flags().StringVarP(&ledgerFile, "ledger-file", "l", "", "record received transactions to a ledger file")

command.Run = func(cmd *cobra.Command, args []string) {

go func() {

if viper.GetString("Dfuse.Protocol") == "WebSocket" {
pkg.StreamWS(channelName, sendReceipts)
} else {
pkg.StreamMessages(context.TODO(), channelName, sendReceipts)
}
pkg.StreamMessages(context.TODO(), channelName, ledgerFile, sendReceipts)
}()

sigs := make(chan os.Signal, 1)
Expand Down
3 changes: 2 additions & 1 deletion configs/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Eosio:
PublishAccount: messengerbus
PublishPrivateKey: 5KAP1zytghuvowgprSPLNasajibZcxf4KMgdgNbrNj98xhcGAUa
Dfuse:
Protocol: GraphQL # only GraphQL supported now # WebSocket will use WSEndpoint; else it defaults to GraphQL
Protocol: GraphQL # only GraphQL supported now
WSEndpoint: wss://kylin.eos.dfuse.io/v1/stream # only GraphQL supported now
Origin: github.com/eosio-enterprise/chappe
ApiKey: <<insert dfuse api key here>>
GraphQLEndpoint: kylin.eos.dfuse.io:443
AuthEndpoint: https://auth.dfuse.io/v1/auth/issue
KeyDirectory: channels/
PublishInterval: 5s # Go Duration object
DeviceRSAPrivateKey: mykey # uniquely represents the device (used for receipts)
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module github.com/eosio-enterprise/chappe
go 1.13

require (
github.com/bxcodec/faker v2.0.1+incompatible
github.com/bxcodec/faker/v3 v3.3.0
github.com/dfuse-io/eosws-go v0.0.0-20191011181529-0eb3d4ce8743
github.com/eoscanada/eos-go v0.9.1-0.20200316040626-bf09fb15dea8
github.com/fatih/color v1.3.0
github.com/golang/protobuf v1.3.3
github.com/ipfs/go-ipfs-api v0.0.3
github.com/leekchan/accounting v0.0.0-20191218023648-17a4ce5f94d4
github.com/multiformats/go-multihash v0.0.10 // indirect
github.com/spf13/cobra v0.0.6
github.com/spf13/viper v1.6.2
Expand Down
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA=
github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM=
github.com/bxcodec/faker/v3 v3.3.0 h1:w/GnJDXnn8b49hLqU948jZj1pqcb8y7sTE822KzO+xc=
github.com/bxcodec/faker/v3 v3.3.0/go.mod h1:gF31YgnMSMKgkvl+fyEo1xuSMbEuieyqfeslGYFjneM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand All @@ -49,6 +49,8 @@ github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgk
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down Expand Up @@ -76,6 +78,7 @@ github.com/eoscanada/eos-go v0.8.5/go.mod h1:RKrm2XzZEZWxSMTRqH5QOyJ1fb/qKEjs2ix
github.com/eoscanada/eos-go v0.9.1-0.20200316040626-bf09fb15dea8 h1:E79CwwnFq70bWq52l7qthwR2uY1EpVSUUojwUVbEgLs=
github.com/eoscanada/eos-go v0.9.1-0.20200316040626-bf09fb15dea8/go.mod h1:6RuJFiRU1figWZ39M33o2cERU2MdL6VllElYLHTZNeo=
github.com/ethereum/go-ethereum v1.9.9/go.mod h1:a9TqabFudpDu1nucId+k9S8R9whYaHnGBLKFouA5EAo=
github.com/fatih/color v1.3.0 h1:YehCCcyeQ6Km0D6+IapqPinWBK6y+0eB5umvZXK9WPs=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand Down Expand Up @@ -153,6 +156,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leekchan/accounting v0.0.0-20191218023648-17a4ce5f94d4 h1:KZzDAtJ7ZLm0zSWVhN/zgyB8Ksx5H+P9irwbTcJ9FwI=
github.com/leekchan/accounting v0.0.0-20191218023648-17a4ce5f94d4/go.mod h1:3timm6YPhY3YDaGxl0q3eaflX0eoSx3FXn7ckHe4tO0=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s=
github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8=
github.com/libp2p/go-libp2p-core v0.0.1 h1:HSTZtFIq/W5Ue43Zw+uWZyy2Vl5WtF0zDjKN8/DT/1I=
Expand All @@ -166,9 +173,11 @@ github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMg
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o=
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 h1:USWjF42jDCSEeikX/G1g40ZWnsPXN5WkZ4jMHZWyBK4=
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
Expand Down Expand Up @@ -239,6 +248,8 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So
github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
Expand Down
11 changes: 5 additions & 6 deletions pkg/dfuse-graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func getToken(apiKey string) (token string, expiration time.Time, err error) {
reqBody := bytes.NewBuffer([]byte(fmt.Sprintf(`{"api_key":"%s"}`, apiKey)))
resp, err := http.Post("https://auth.dfuse.io/v1/auth/issue", "application/json", reqBody)
resp, err := http.Post(viper.GetString("Dfuse.AuthEndpoint"), "application/json", reqBody)
if err != nil {
err = fmt.Errorf("unable to obtain token: %s", err)
return
Expand Down Expand Up @@ -86,7 +86,7 @@ type eosioDocument struct {
}

// StreamMessages ...
func StreamMessages(ctx context.Context, channelName string, sendReceipts bool) {
func StreamMessages(ctx context.Context, channelName, ledgerFile string, sendReceipts bool) {
/* The client can be re-used for all requests, cache it at the appropriate level */
client := createClient(viper.GetString("Dfuse.GraphQLEndpoint"))
executor, err := client.Execute(ctx, &pb.Request{Query: operationEOS})
Expand Down Expand Up @@ -131,7 +131,7 @@ func StreamMessages(ctx context.Context, channelName string, sendReceipts bool)
if payload["message_type"] == "receipt" {
log.Println("Received receipt, ignoring.")
} else {
message, err := receiveGQL(channelName, payload)
message, err := receiveGQL(channelName, ledgerFile, payload)
if err == nil && sendReceipts {
SendReceipt(channelName, message)
}
Expand All @@ -141,13 +141,12 @@ func StreamMessages(ctx context.Context, channelName string, sendReceipts bool)
}
}

func receiveGQL(channelName string, payload map[string]string) (Message, error) {
// log.Println(payload)
func receiveGQL(channelName, ledgerFile string, payload map[string]string) (Message, error) {
var msg Message
cid, cidExists := payload["cid"]
if cidExists {
log.Println("Received notification of new message: ", payload["cid"], "; memo: ", payload["memo"])
msg, err := Load(channelName, cid)
msg, err := Load(channelName, ledgerFile, cid)
if err != nil {
log.Println("Error loading message: ", err)
return msg, err
Expand Down
92 changes: 0 additions & 92 deletions pkg/dfuse-websocket.go

This file was deleted.

Loading

0 comments on commit 3dbffc7

Please sign in to comment.