Skip to content

Commit

Permalink
Merge pull request #825 from mikiquantum/master
Browse files Browse the repository at this point in the history
Merge develop
  • Loading branch information
mikiquantum authored Mar 7, 2019
2 parents d84a5a3 + e4eacc6 commit 7383995
Show file tree
Hide file tree
Showing 243 changed files with 12,646 additions and 12,216 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ coverage/
coverage.txt
*.swp
*.swo
testworld/peerconfigs/*
testworld/hostconfigs/*
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cache:
- /tmp/depcache

before_install:
- nvm install 10.15.1
- npm install -g [email protected]

install:
Expand Down
19 changes: 11 additions & 8 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,24 @@ required = ["github.com/centrifuge/centrifuge-ethereum-contracts", "github.com/r

[[constraint]]
name = "github.com/centrifuge/centrifuge-protobufs"
revision = "f93686ceaf40283c7dc496c62fcc69b1c1a272e3"
revision = "20c7fd5e4210e68d2a5662a8714d51ceeae031b8"

[[override]]
name = "github.com/centrifuge/centrifuge-ethereum-contracts"
revision = "978840734a4a2fccd5d8dc7e462d9108079c5b5d"
revision = "be1a93f627115fcf9978a85c4b6b8f08adf87f35"

[[constraint]]
name = "github.com/Masterminds/semver"
version = "1.4.2"

[[override]]
name = "github.com/centrifuge/precise-proofs"
revision = "8c3b6a26b7929ec269302dc50d17c9ceb9772dda"
revision = "13d3af957299c614237c42cdc331f7acd7c7d201"

[[constraint]]
name = "github.com/centrifuge/gocelery"
revision = "fb11151a227ae41660e15f6c10e2e22eb1556531"

[[override]]
name = "github.com/xsleonard/go-merkle"
revision = "fbb7cafc5ae411e13e718172f5af7917ad6c3ed7"

[[override]]
name = "github.com/ethereum/go-ethereum"
revision = "d2328b604a2d4ecdccc47d8f9133593161cbd40a"
Expand Down
50 changes: 40 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
TRAVIS_BRANCH?=`git rev-parse --abbrev-ref HEAD`
GIT_COMMIT=`git rev-parse HEAD`
GIT_SHORT_COMMIT=`git rev-parse --short HEAD`
TIMESTAMP=`date -u +%Y%m%d%H`
TIMESTAMP=`date -u +%Y%m%d%H%M%S`
TAG="${TRAVIS_BRANCH}-${TIMESTAMP}-${GIT_SHORT_COMMIT}"
IMAGE_NAME?=centrifugeio/go-centrifuge
LD_FLAGS?="-X github.com/centrifuge/go-centrifuge/version.gitCommit=${GIT_COMMIT}"
GCLOUD_SERVICE?="./build/peak-vista-185616-9f70002df7eb.json"

# GOBIN needs to be set to ensure govendor can actually be found and executed
# Default TAGINSTANCE for standalone targets
TAGINSTANCE="${TAG}"

# GOBIN needs to be set to ensure govendor can actually be found and executed
PATH=$(shell printenv PATH):$(GOBIN)

# If you need to overwrite PROTOTOOL_BIN, you can set this environment variable.
PROTOTOOL_BIN ?=$(shell which prototool)

# Lock metalinter version
GOMETALINTER_VERSION="v2.0.12"

.PHONY: help

Expand All @@ -22,15 +27,20 @@ help: ## Show this help message.
@echo 'targets:'
@egrep '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#'

clean: ##clean vendor's folder. Should be run before a make install
@echo 'cleaning previous /vendor folder'
@rm -rf vendor/
@echo 'done cleaning'

install-deps: ## Install Dependencies
@command -v dep >/dev/null 2>&1 || go get -u github.com/golang/dep/...
@dep ensure
@npm --prefix ./build install
@curl -L https://git.io/vp6lP | sh
@curl -L https://git.io/vp6lP | sh -s ${GOMETALINTER_VERSION}
@mv ./bin/* $(GOPATH)/bin/; rm -rf ./bin

lint-check: ## runs linters on go code
@gometalinter --disable-all --enable=golint --enable=goimports --enable=vet --enable=nakedret \
@gometalinter --exclude=anchors/service.go --disable-all --enable=golint --enable=goimports --enable=vet --enable=nakedret \
--enable=staticcheck --vendor --skip=resources --skip=testingutils --skip=protobufs --deadline=1m ./...;

format-go: ## formats go code
Expand All @@ -56,8 +66,27 @@ vendorinstall: ## Installs all protobuf dependencies with go-vendorinstall
go-vendorinstall github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go-vendorinstall github.com/golang/protobuf/protoc-gen-go
go-vendorinstall github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go-vendorinstall golang.org/x/tools/cmd/goimports
go get -u github.com/jteeuwen/go-bindata/...

abigen-install: ## Installs ABIGEN from vendor
abigen-install: vendorinstall
go-vendorinstall github.com/ethereum/go-ethereum/cmd/abigen

gen-abi-bindings: ## Generates GO ABI Bindings
gen-abi-bindings: install-deps abigen-install
$(eval CONTRACTS_VERSION := $(shell cat vendor/github.com/centrifuge/centrifuge-ethereum-contracts/package.json | jq -r '.version'))
npm install --prefix tmp/contracts @centrifuge/ethereum-contracts@${CONTRACTS_VERSION}
@cat tmp/contracts/node_modules/\@centrifuge/ethereum-contracts/build/contracts/Identity.json | jq '.abi' > tmp/contracts/id.abi
@cat tmp/contracts/node_modules/\@centrifuge/ethereum-contracts/build/contracts/AnchorRepository.json | jq '.abi' > tmp/contracts/ar.abi
@cat tmp/contracts/node_modules/\@centrifuge/ethereum-contracts/build/contracts/PaymentObligation.json | jq '.abi' > tmp/contracts/po.abi
@cat tmp/contracts/node_modules/\@centrifuge/ethereum-contracts/build/contracts/IdentityFactory.json | jq '.abi' > tmp/contracts/idf.abi
@abigen --abi tmp/contracts/id.abi --pkg ideth --type IdentityContract --out ${GOPATH}/src/github.com/centrifuge/go-centrifuge/identity/ideth/identity_contract.go
@abigen --abi tmp/contracts/ar.abi --pkg anchors --type AnchorContract --out ${GOPATH}/src/github.com/centrifuge/go-centrifuge/anchors/anchor_contract.go
@abigen --abi tmp/contracts/po.abi --pkg nft --type EthereumPaymentObligationContract --out ${GOPATH}/src/github.com/centrifuge/go-centrifuge/nft/ethereum_payment_obligation_contract.go
@abigen --abi tmp/contracts/idf.abi --pkg ideth --type FactoryContract --out ${GOPATH}/src/github.com/centrifuge/go-centrifuge/identity/ideth/factory_contract.go
@rm -Rf ./tmp

install: ## Builds and Install binary for development
install: install-deps vendorinstall
@go install ./cmd/centrifuge/...
Expand All @@ -72,20 +101,21 @@ build-linux-amd64: install-xgo
@mkdir -p build/linux-amd64
@xgo -go 1.11.x -dest build/linux-amd64 -targets=linux/amd64 -ldflags=${LD_FLAGS} ./cmd/centrifuge/
@mv build/linux-amd64/centrifuge-linux-amd64 build/linux-amd64/centrifuge
@tar -zcvf cent-api-linux-amd64-${TAG}.tar.gz -C build/linux-amd64/ .
$(eval TAGINSTANCE := $(shell echo ${TAG}))
@tar -zcvf cent-api-linux-amd64-${TAGINSTANCE}.tar.gz -C build/linux-amd64/ .

build-docker: ## Build Docker Image
build-docker:
@echo "Building Docker Image"
@docker build -t ${IMAGE_NAME}:${TAG} .
@docker build -t ${IMAGE_NAME}:${TAGINSTANCE} .

build-ci: ## Builds + Push all artifacts
build-ci: build-linux-amd64 build-docker
@echo "Building/Pushing Artifacts for CI"
@gcloud auth activate-service-account --key-file ${GCLOUD_SERVICE}
@gsutil cp cent-api-*-${TAG}.tar.gz gs://centrifuge-artifact-releases/
@gsutil acl ch -u AllUsers:R gs://centrifuge-artifact-releases/cent-api-*-${TAG}.tar.gz
@gsutil cp cent-api-*-${TAGINSTANCE}.tar.gz gs://centrifuge-artifact-releases/
@gsutil acl ch -u AllUsers:R gs://centrifuge-artifact-releases/cent-api-*-${TAGINSTANCE}.tar.gz
@echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
@docker tag "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:latest"
@docker tag "${IMAGE_NAME}:${TAGINSTANCE}" "${IMAGE_NAME}:latest"
@docker push ${IMAGE_NAME}:latest
@docker push ${IMAGE_NAME}:${TAG}
@docker push ${IMAGE_NAME}:${TAGINSTANCE}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Centrifuge OS node

[![Build Status](https://travis-ci.com/centrifuge/go-centrifuge.svg?token=Sbf68xBZUZLMB3kGTKcX&branch=master)](https://travis-ci.com/centrifuge/go-centrifuge)
[![Go Report Card](https://goreportcard.com/badge/github.com/centrifuge/go-centrifuge)](https://goreportcard.com/report/github.com/centrifuge/go-centrifuge)

`go-centrifuge` is the go implementation of the Centrifuge OS interacting with the peer to peer network and our Ethereum smart contracts.

Expand Down
34 changes: 15 additions & 19 deletions anchors/anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/centrifuge/go-centrifuge/errors"
"github.com/centrifuge/go-centrifuge/identity"
"github.com/centrifuge/go-centrifuge/utils"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)

Expand Down Expand Up @@ -49,6 +50,11 @@ func (a *AnchorID) BigInt() *big.Int {
return utils.ByteSliceToBigInt(a[:])
}

// String returns anchorID in string form
func (a *AnchorID) String() string {
return hexutil.Encode(a[:])
}

// DocumentRoot type is byte array of length DocumentRootLength
type DocumentRoot [DocumentRootLength]byte

Expand All @@ -72,22 +78,17 @@ func RandomDocumentRoot() DocumentRoot {

// PreCommitData holds required document details for pre-commit
type PreCommitData struct {
AnchorID AnchorID
SigningRoot DocumentRoot
CentrifugeID identity.CentID
Signature []byte
ExpirationBlock *big.Int
SchemaVersion uint
AnchorID AnchorID
SigningRoot DocumentRoot
SchemaVersion uint
}

// CommitData holds required document details for anchoring
type CommitData struct {
BlockHeight uint64
AnchorID AnchorID
DocumentRoot DocumentRoot
CentrifugeID identity.CentID
DocumentProofs [][DocumentProofLength]byte
Signature []byte
SchemaVersion uint
}

Expand All @@ -109,31 +110,26 @@ func supportedSchemaVersion() uint {
}

// newPreCommitData returns a PreCommitData with passed in details
func newPreCommitData(anchorID AnchorID, signingRoot DocumentRoot, centrifugeID identity.CentID, signature []byte, expirationBlock *big.Int) (preCommitData *PreCommitData) {
func newPreCommitData(anchorID AnchorID, signingRoot DocumentRoot) (preCommitData *PreCommitData) {
return &PreCommitData{
AnchorID: anchorID,
SigningRoot: signingRoot,
CentrifugeID: centrifugeID,
Signature: signature,
ExpirationBlock: expirationBlock,
SchemaVersion: supportedSchemaVersion(),
AnchorID: anchorID,
SigningRoot: signingRoot,
SchemaVersion: supportedSchemaVersion(),
}
}

// NewCommitData returns a CommitData with passed in details
func NewCommitData(blockHeight uint64, anchorID AnchorID, documentRoot DocumentRoot, centrifugeID identity.CentID, documentProofs [][32]byte, signature []byte) (commitData *CommitData) {
func NewCommitData(blockHeight uint64, anchorID AnchorID, documentRoot DocumentRoot, documentProofs [][32]byte) (commitData *CommitData) {
return &CommitData{
BlockHeight: blockHeight,
AnchorID: anchorID,
DocumentRoot: documentRoot,
CentrifugeID: centrifugeID,
DocumentProofs: documentProofs,
Signature: signature,
}
}

// GenerateCommitHash generates Keccak256 message from AnchorID, CentID, DocumentRoot
func GenerateCommitHash(anchorID AnchorID, centrifugeID identity.CentID, documentRoot DocumentRoot) []byte {
func GenerateCommitHash(anchorID AnchorID, centrifugeID identity.DID, documentRoot DocumentRoot) []byte {
msg := append(anchorID[:], documentRoot[:]...)
msg = append(msg, centrifugeID[:]...)
return crypto.Keccak256(msg)
Expand Down
Loading

0 comments on commit 7383995

Please sign in to comment.