Skip to content

Commit

Permalink
Start balance related database code
Browse files Browse the repository at this point in the history
  • Loading branch information
sambarnes committed Sep 30, 2019
1 parent efa450e commit 7b097d3
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 15 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ module github.com/pegnet/pegnetd
go 1.13

require (
github.com/AdamSLevy/jsonrpc2/v11 v11.3.2
github.com/Factom-Asset-Tokens/factom v0.0.0-20190911201853-7b283996f02a
github.com/Factom-Asset-Tokens/fatd v0.6.1-0.20190927200133-81408234a2b5
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d
github.com/mattn/go-sqlite3 v1.11.0
github.com/pegnet/pegnet v0.1.0-rc4.0.20190924093136-5a53cdfd85af
github.com/rs/cors v1.7.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.4.0
)

replace github.com/Factom-Asset-Tokens/factom => github.com/Emyrk/factom v0.0.0-20190930143628-2ee99fcbdc03
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
crawshaw.io/iox v0.0.0-20181124134642-c51c3df30797 h1:yDf7ARQc637HoxDho7xjqdvO5ZA2Yb+xzv/fOnnvZzw=
crawshaw.io/iox v0.0.0-20181124134642-c51c3df30797/go.mod h1:sXBiorCo8c46JlQV3oXPKINnZ8mcqnye1EkVkqsectk=
crawshaw.io/sqlite v0.1.2/go.mod h1:BZaitnE9BVpocOuCdi/y5XReJMUelG53e/rDSLwSFzY=
crawshaw.io/sqlite v0.1.3-0.20190520153332-66f853b01dfb h1:jKjr7R+PV9y9zuht2we+zbgGtsk8XiL1c8BhupMaYRQ=
crawshaw.io/sqlite v0.1.3-0.20190520153332-66f853b01dfb/go.mod h1:igAO5JulrQ1DbdZdtVq48mnZUBAPOeFzer7VhDWNtW4=
github.com/AdamSLevy/go-merkle v0.0.0-20190611101253-ca33344a884d h1:FWutTJGVqBnL4rLgeNaspUYnmnvkXcmDA3QO3rHBGgU=
github.com/AdamSLevy/go-merkle v0.0.0-20190611101253-ca33344a884d/go.mod h1:Nw3sh5L40Xs1wno7ndbD/dYWg+vARpBvpX9Zz1YSxbo=
github.com/AdamSLevy/jsonrpc2 v2.0.0+incompatible h1:ut4YIGFeO2Mzyj7pNEmcHBAm/88qCDmZMyUn6EeuXI4=
Expand All @@ -7,12 +12,16 @@ github.com/AdamSLevy/jsonrpc2/v11 v11.3.2 h1:McSW/pP7K0/Ucjig6AJwW7Khph/XOMYhSB8
github.com/AdamSLevy/jsonrpc2/v11 v11.3.2/go.mod h1:7fNjH6BXM0KVswWqj+K/mnOS8wiSke0sE8X46hS+nsc=
github.com/AdamSLevy/jsonrpc2/v12 v12.0.0 h1:2CO5yc4+4cfm6rvLl4pVPqaNLqbdHkcchK15p3aFxkg=
github.com/AdamSLevy/jsonrpc2/v12 v12.0.0/go.mod h1:sE4iA2g7QxE9xbNXpijPrdZrhmB9hJript+gL+ZzUS4=
github.com/AdamSLevy/sqlitechangeset v0.0.0-20190925183646-3ddb70fb709d h1:yPm4An70OhM4k4WUq7M9sWaVlFas2+hJB+I3Fsgw38A=
github.com/AdamSLevy/sqlitechangeset v0.0.0-20190925183646-3ddb70fb709d/go.mod h1:kQNmmf+2gf3uGKHt0LS4guxdp4Ay44SXA4+Is8/Gxm8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Emyrk/factom v0.0.0-20190930143628-2ee99fcbdc03 h1:352DtdTKdyJFd2KkjhgpJMqt/SLUkSurvXs2gmqPUIU=
github.com/Emyrk/factom v0.0.0-20190930143628-2ee99fcbdc03/go.mod h1:Wi7bcGLU3lhoVG9TuzKxxRSSqlXiHFKjPr0WsOyezCs=
github.com/Factom-Asset-Tokens/base58 v0.0.0-20181227014902-61655c4dd885 h1:rfy2fwMrOZPqQgjsH7VCreGMSPzcvqQrfjeSs8nf+sY=
github.com/Factom-Asset-Tokens/base58 v0.0.0-20181227014902-61655c4dd885/go.mod h1:RVXsRSp6VzXw5l1uiGazuf3qo23Qk0h1HzMcQk+X4LE=
github.com/Factom-Asset-Tokens/fatd v0.6.1-0.20190927200133-81408234a2b5 h1:nJgckkWLVJxlZyfc5Wv8unMV9QmOQz6InW87MU8x0fg=
github.com/Factom-Asset-Tokens/fatd v0.6.1-0.20190927200133-81408234a2b5/go.mod h1:BtAPS0V7pjfxo1rdQ+ZKiW8QYBxDcVskMxkY3JKQsqw=
github.com/FactomProject/FactomCode v0.3.5/go.mod h1:7XksVta7THNbD031Ax0/dS5RKMS+ug+d7/Lmti8jAhE=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
Expand Down Expand Up @@ -49,7 +58,9 @@ github.com/FactomProject/netki-go-partner-client v0.0.0-20160324224126-426acb535
github.com/FactomProject/serveridentity v0.0.0-20180611231115-cf42d2aa8deb/go.mod h1:qPNpznGlx4PdRmEL7I25U/zQHrbMK1h0Az8FYahuYdo=
github.com/FactomProject/web v0.1.0/go.mod h1:wiLhlN8amF4dalkSy+u75C3xsXaesSHy2cph6b/8PrI=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alexandrevicenzi/go-sse v0.0.0-20190531224209-805eefa457e7 h1:HF2BoTaOEJzRl1WV+epnYM+kGi4DD87mVyQlWbkVLgA=
github.com/alexandrevicenzi/go-sse v0.0.0-20190531224209-805eefa457e7/go.mod h1:BLBuvd1uY9dCX660zu1fzsmr0Cqt3VPqK1e5fPfV6wc=
Expand Down Expand Up @@ -92,6 +103,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d h1:lBXNCxVENCipq4D1Is42JVOP4eQjlB8TQ6H69Yx5J9Q=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
Expand All @@ -109,7 +122,11 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
Expand All @@ -126,6 +143,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -144,6 +163,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443 h1:+2OJrU8cmOstEoh0uQvYemRGVH1O6xtO2oANUWHFnP0=
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443/go.mod h1:JbxfV1Iifij2yhRjXai0oFrbpxszXHRx1E5RuM26o4Y=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -163,19 +184,24 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI=
github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
Expand All @@ -201,6 +227,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
Expand Down Expand Up @@ -254,6 +281,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/p
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190911201528-7ad0cfa0b7b5 h1:SW/0nsKCUaozCUtZTakri5laocGx/5bkDSSLrFUsa5s=
golang.org/x/sys v0.0.0-20190911201528-7ad0cfa0b7b5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand All @@ -274,6 +303,7 @@ google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmE
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
Expand Down
18 changes: 3 additions & 15 deletions node/node.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package node

import (
"database/sql"
"os"

"github.com/Factom-Asset-Tokens/factom"
_ "github.com/mattn/go-sqlite3"
"github.com/pegnet/pegnet/modules/grader"
Expand All @@ -23,9 +20,6 @@ type Pegnetd struct {
Sync BlockSync

Pegnet *pegnet.Pegnet

// This is the sqlite db to store state
DB *sql.DB
}

func NewPegnetd(conf *viper.Viper) (*Pegnetd, error) {
Expand All @@ -44,21 +38,15 @@ func NewPegnetd(conf *viper.Viper) (*Pegnetd, error) {
}

n.Pegnet = pegnet.New(conf)
if err := n.Pegnet.Init(); err != nil {
return nil, err
}

// TODO: Check this, harcoding it high to skip the initial stuff
n.Sync.Synced = 206421

// TODO :Is this the spot spot to init?
grader.InitLX()

// Load the sqldb (or create it)
path := os.ExpandEnv(viper.GetString(config.SqliteDBPath))
// TODO: Idc which sqlite to use. Change this if you want.
db, err := sql.Open("sqlite3", path)
if err != nil {
return nil, err
}
n.DB = db

return n, nil
}
90 changes: 90 additions & 0 deletions node/pegnet/addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package pegnet

import (
"github.com/Factom-Asset-Tokens/factom"
"github.com/pegnet/pegnetd/fat/fat2"
)

const createTableAddresses = `CREATE TABLE "pn_addresses" (
"id" INTEGER PRIMARY KEY,
"address" BLOB NOT NULL UNIQUE,
"peg_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("peg_balance" >= 0),
"pusd_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pusd_balance" >= 0),
"peur_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("peur_balance" >= 0),
"pjpy_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pjpy_balance" >= 0),
"pgbp_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pgbp_balance" >= 0),
"pcad_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pcad_balance" >= 0),
"pchf_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pchf_balance" >= 0),
"pinr_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pinr_balance" >= 0),
"psgd_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("psgd_balance" >= 0),
"pcny_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pcny_balance" >= 0),
"phkd_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("phkd_balance" >= 0),
"pkrw_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pkrw_balance" >= 0),
"pbrl_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pbrl_balance" >= 0),
"pphp_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pphp_balance" >= 0),
"pmxn_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pmxn_balance" >= 0),
"pxau_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pxau_balance" >= 0),
"pxag_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pxag_balance" >= 0),
"pxbt_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pxbt_balance" >= 0),
"peth_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("peth_balance" >= 0),
"pltc_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pltc_balance" >= 0),
"prvn_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("prvn_balance" >= 0),
"pxbc_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pxbc_balance" >= 0),
"pfct_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pfct_balance" >= 0),
"pbnb_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pbnb_balance" >= 0),
"pxlm_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pxlm_balance" >= 0),
"pada_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pada_balance" >= 0),
"pxmr_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pxmr_balance" >= 0),
"pdas_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pdas_balance" >= 0),
"pzec_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pzec_balance" >= 0),
"pdcr_balance" INTEGER NOT NULL
CONSTRAINT "insufficient balance" CHECK ("pdcr_balance" >= 0)
);
`

func (p *Pegnet) CreateTableAddresses() error {
_, err := p.DB.Exec(createTableAddresses)
if err != nil {
return err
}
return nil
}

func (p *Pegnet) AddToBalance(adr *factom.FAAddress, ticker fat2.PTicker, add uint64) (int64, error) {
// TODO: implement AddToBalance
return 0, nil
}

func (p *Pegnet) SubFromBalance(adr *factom.FAAddress, ticker fat2.PTicker, add uint64) (int64, error) {
// TODO: implement SubFromBalance
return 0, nil
}
31 changes: 31 additions & 0 deletions node/pegnet/pegnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package pegnet

import (
"container/list"
"database/sql"
"fmt"
"github.com/pegnet/pegnetd/config"
"os"
"os/user"

"github.com/pegnet/pegnet/modules/grader"

Expand All @@ -13,6 +18,9 @@ type Pegnet struct {

// TODO: Make this a database
PegnetChain *list.List

// This is the sqlite db to store state
DB *sql.DB
}

func New(conf *viper.Viper) *Pegnet {
Expand All @@ -23,6 +31,29 @@ func New(conf *viper.Viper) *Pegnet {
return p
}

func (p *Pegnet) Init() error {
path := os.ExpandEnv(viper.GetString(config.SqliteDBPath))
usr, err := user.Current()
if err != nil {
return err
}
path = fmt.Sprintf("%s/%s", usr.HomeDir, path)
// TODO: Idc which sqlite to use. Change this if you want.T
db, err := sql.Open("sqlite3", path)
if err != nil {
return err
}
p.DB = db
err = p.CreateTableAddresses()
if err != nil {
// TODO: implement better schema validation
if err.Error() != "table \"pn_addresses\" already exists" {
return err
}
}
return nil
}

func (p *Pegnet) InsertGradedBlock(block grader.GradedBlock) {
p.PegnetChain.PushBack(block)
}
Expand Down
1 change: 1 addition & 0 deletions pegnetd-conf.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Pegnetd config file
[app]
loglevel = "info"
dbpath = ".pegnet/node.db"

[dblocksync]
retry = "5s"

0 comments on commit 7b097d3

Please sign in to comment.