Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeniy Kulikov committed Nov 18, 2019
0 parents commit 1cf33e5
Show file tree
Hide file tree
Showing 87 changed files with 29,835 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**/*.pb.go -diff binary
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
temp
/vendor/
675 changes: 675 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
protoc:
@go mod tidy -v
@go mod vendor
# Install specific version for gogo-proto
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/gogo/protobuf | xargs go get -v
# Install specific version for protobuf lib
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go get -v
# Protoc generate
@find . -type f -name '*.proto' -not -path './vendor/*' \
-exec protoc \
--proto_path=.:./vendor \
--gofast_out=plugins=grpc,paths=source_relative:. '{}' \;
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# NeoFS-proto

NeoFS-proto repository contains implementation of core NeoFS structures that
can be used for integration with NeoFS.

## Description

Repository contains 13 packages that implement NeoFS core structures. These
packages mostly contain protobuf files with service and structure definitions
or NeoFS core types with complemented functions.

### Accounting

Accounting package defines services and structures for accounting operations:
balance request and `cheque` operations for withdraw. `Cheque` is a structure
with inner ring signatures, which approve that user can withdraw requested
amount of assets. NeoFS smart contract takes binary formatted `cheque` as a
parameter in withdraw call.

### Bootstrap

Bootstrap package defines bootstrap service which is used by storage nodes to
connect to the storage network.

### Chain

Chain package contains util functions for operations with NEO Blockchain types:
wallet addresses, script-hashes.

### Container

Container package defines service and structures for operations with containers.
Objects in NeoFS are stored in containers. Container defines storage
policy for the objects.

### Decimal

Decimal defines custom decimal implementation which is used in accounting
operations.

### Hash

Hash package defines homomorphic hash type.

### Internal

Internal package defines constant error type and proto interface for custom
protobuf structures.

### Object

Object package defines service and structures for object operations. Object is
a core storage structure in NeoFS. Package contains detailed information
about object internal structure.

### Query

Query package defines structure for object search requests.

### Refs

Refs package defines core identity types: Object ID, Container ID, etc.

### Service

Service package defines util structure and functions for all NeoFS services
operations: TTL and request signature management, node roles, epoch retriever.

### Session

Session package defines service and structures for session obtain. Object
operations require an established session with pair of session keys signed by
owner of the object.

### State

State package defines service and structures for metrics gathering.

## How to use

NeoFS-proto packages contain godoc documentation. Examples of using most of
these packages can be found in NeoFS-CLI repository. CLI implements and
demonstrates all basic interactions with NeoFS: container, object, storage
group, and accounting operations.

Protobuf files are recompiled with the command:

```
$ make protoc
```

## Contributing

At this moment, we do not accept contributions.

## License

This project is licensed under the GPLv3 License -
see the [LICENSE.md](LICENSE.md) file for details
8 changes: 8 additions & 0 deletions accounting/fixtures/cheque.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

CHEQUE=d6520dabb6cb9b981792608c73670eff14775e9a65bbc189271723ba2703c53263e8d6e522dc32203339dcd8eee9c6b7439a0000000053724e000000000000001e61000603012d47e76210aec73be39ab3d186e0a40fe8d86bfa3d4fabfda57ba13b88f96abe1de4c7ecd46cb32081c0ff199e0b32708d2ce709dd146ce096484073a9b15a259ca799f8d848eb5bea16f6d0842a0181ccd47384af2cdb0fd0af0819e8a08802f7528ce97c9a93558efe7d4f62577aabdf771c931f54a71be6ad21e7d9cc1777686ad19b5dc4b80d7b8decf90054c5aad66c0e6fe63d8473b751cd77c1bd0557516e0f3e7d0ccb485809023b0c08a89f33ae38b2f99ce3f1ebc7905dddf0ed0f023e00f03a16e8707ce045eb42ee80d392451541ee510dc18e1c8befbac54d7426087d37d32d836537d317deafbbd193002a36f80fbdfbf3a730cf011bc6c75c7e6d5724f3adee7015fcb3068d321e2ae555e79107be0c46070efdae2f724dbc9f0340750b92789821683283bcb98e32b7e032b94f267b6964613fc31a7ce5813fddeea47a1db525634237e924178b5c8ea745549ae60aa3570ce6cf52e370e6ab87652bdf8a179176f1acaf48896bef9ab300818a53f410d86241d506a550f4915403fef27f744e829131d0ec980829fafa51db1714c2761d9f78762c008c323e9d6612e4f9efdc609f191fd9ca5431dd9dc037130150107ab8769780d728e9ffdf314019b57c8d2b940b9ec078afa951ed8b06c1bf352edd2037e29b8f24cca3ec700368a6f5829fb2a34fa03d0308ae6b05f433f2904d9a852fed1f5d2eb598ca79475b74ef6394e712d275cd798062c6d8e41fad822ac5a4fcb167f0a2e196f61f9f65a0adef9650f49150e7eb7bb08dd1739fa6e86b341f1b2cf5657fcd200637e8
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

echo $CHEQUE | xxd -p -r > $DIR/cheque_data

exit 0
Binary file added accounting/fixtures/cheque_data
Binary file not shown.
49 changes: 49 additions & 0 deletions accounting/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package accounting

import (
"github.com/nspcc-dev/neofs-proto/decimal"
"github.com/nspcc-dev/neofs-proto/internal"
"github.com/nspcc-dev/neofs-proto/refs"
)

type (
// OwnerID type alias.
OwnerID = refs.OwnerID

// Decimal type alias.
Decimal = decimal.Decimal

// Filter is used to filter accounts by criteria.
Filter func(acc *Account) bool
)

const (
// ErrEmptyAddress is raised when passed Address is empty.
ErrEmptyAddress = internal.Error("empty address")

// ErrEmptyLockTarget is raised when passed LockTarget is empty.
ErrEmptyLockTarget = internal.Error("empty lock target")

// ErrEmptyContainerID is raised when passed CID is empty.
ErrEmptyContainerID = internal.Error("empty container ID")

// ErrEmptyParentAddress is raised when passed ParentAddress is empty.
ErrEmptyParentAddress = internal.Error("empty parent address")
)

// SetTTL sets ttl to BalanceRequest to satisfy TTLRequest interface.
func (m BalanceRequest) SetTTL(v uint32) { m.TTL = v }

// SumFunds goes through all accounts and sums up active funds.
func SumFunds(accounts []*Account) (res *decimal.Decimal) {
res = decimal.Zero.Copy()

for i := range accounts {
if accounts[i] == nil {
continue
}

res = res.Add(accounts[i].ActiveFunds)
}
return
}
Loading

0 comments on commit 1cf33e5

Please sign in to comment.