Giter VIP home page Giter VIP logo

protobuf-schemas's Introduction

About

Waves protobuf schemas repository

How to use

Java

Add dependency to your pom.xml

<dependency>
    <groupId>com.wavesplatform</groupId>
    <artifactId>protobuf-schemas</artifactId>
    <version>{version}</version>
</dependency>

ScalaPB

  1. Add dependency to your build.sbt:
libraryDependencies += "com.wavesplatform" % "protobuf-schemas" % "{version}" % "protobuf-src" intransitive()
  1. Configure ScalaPB to compile external schemas with:
inConfig(Compile)(Seq(
   PB.protoSources in Compile := Seq(PB.externalIncludePath.value),
   includeFilter in PB.generate := new SimpleFileFilter((f: File) => f.getName.endsWith(".proto") && f.getParent.endsWith("waves")),
   PB.targets += scalapb.gen(flatPackage = true) -> sourceManaged.value
 ))
  1. If you use SNAPSHOT version, add this line
resolvers += Resolver.sonatypeRepo("snapshots")

See ScalaPB docs for more info.

JavaScript

Npm package: @waves/protobuf-serialization.

It contains generated JavaScript classes, TypeScript definitions as well as raw proto files. The default build uses CommonJS and includes all of the proto files. We used pbjs to build JavaScript and pbts to build TypeScript definitions.

You could also make your own custom build from raw .proto files, for example, if you want to use only a subset of proto schemas or gRPC services. They can be found in @waves/protobuf-serialization/proto directory.

long.js is used for 64-bit integers: int64, uint64, etc.

Example:

  1. npm install --save @waves/protobuf-serialization
  2. Default build usage
import { waves } from '@waves/protobuf-serialization';

const block = new waves.Block();
block.header = // ... set necessary fields

const buffer = waves.Block.encode(block);

const blockDecoded = waves.Block.decode(buffer);

C#

  1. Add App.config, packages.config to your C# solution
  2. Add
  <ItemGroup>
    <Protobuf Include="proto\waves\*.proto" OutputDir="waves\%(RelativePath)" GrpcServices="None" />
    <Protobuf Include="proto\waves\events\*.proto" OutputDir="waves\events\%(RelativePath)" GrpcServices="None" />
    <Protobuf Include="proto\waves\node\grpc\*.proto" OutputDir="waves\node\grpc\%(RelativePath)" GrpcServices="Both" />
  </ItemGroup>

to your .csproj file. After this just build your project.

or as alternative you can use util protoc, for example: protoc --csharp_out=RelativePath --proto_path=RelativePathToProtoDir RelativePathToProtoFile

Also there is a NuGet package WavesPlatform.ProtobufSchema with this project.

Rust

Add dependency to your Cargo.toml

[dependencies]
waves-protobuf-schemas = { git = "https://github.com/wavesplatform/protobuf-schemas" }

How to generate sources locally

Java

Use mvn package to create JAR artifacts:

  1. protobuf-schemas-{version}-protobuf-src.jar - raw .proto files
  2. protobuf-schemas-{version}.jar - protoc-generated Java classes

Python

Generating python sources requires python 3 or later. Run the following commands from the root of this repository to generate python sources in /target/python:

python3 -m venv .venv
. .venv/bin/activate
pip install grpcio grpcio-tools base58
git clone https://github.com/wavesplatform/protobuf-schemas.git
python -m grpc_tools.protoc --proto_path=./protobuf-schemas/proto --python_out=. --grpc_python_out=. `find ./protobuf-schemas/proto -type f`

Tweak --python_out and --grpc_python_out parameters to generate files elsewhere. Target path should likely be absolute. Now you can use generated classes:

import grpc
from waves.events.grpc.blockchain_updates_pb2_grpc import BlockchainUpdatesApiStub
from waves.events.grpc.blockchain_updates_pb2 import SubscribeRequest
from base58 import b58encode, b58decode

def asset_id(asset_id_bytes):
    return len(asset_id_bytes) > 0 and b58encode(asset_id_bytes) or 'WAVES'

def print_update(update):
    update_id = b58encode(update.id)
    print(f'block {update_id}:')
    for (tx_id, tx_state_update) in zip(update.append.transaction_ids, update.append.transaction_state_updates):
        print(f'  tx {b58encode(tx_id)}:')
        for balance in tx_state_update.balances:
            print(f'    {b58encode(balance.address)}: {balance.amount_before} -> {balance.amount_after.amount} [{asset_id(balance.amount_after.asset_id)}]')

with grpc.insecure_channel('grpc.wavesnodes.com:6881') as channel:
    for block in BlockchainUpdatesApiStub(channel).Subscribe(SubscribeRequest(from_height=3135450, to_height=3135470)):
        print_update(block.update)

protobuf-schemas's People

Contributors

a-kordys avatar alxndrmkd avatar chepiov avatar dependabot[bot] avatar dvshur avatar gingerabsurdity avatar ivan-mashonskiy avatar karasiq avatar nickeskov avatar phearnot avatar potan avatar stuffy-idler avatar vsuharnikov avatar xrtm000 avatar zer0main avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protobuf-schemas's Issues

[BUG] Conflict register for file "transaction.proto"

While running given example in Python 3.8, following issue occurs

TypeError: Conflict register for file "transaction.proto": waves.SignedTransaction is already defined in file "waves/transaction.proto". Please fix the conflict by adding package name on the proto file, or use different name for the duplication.

Protocol message had too many levels of nesting [BUG]

Hello! I'm using WavesJ and the generated proto classes. Here's my code:

BlockchainUpdatesApiGrpc.BlockchainUpdatesApiStub stub = BlockchainUpdatesApiGrpc.newStub(channel);

BlockchainUpdates.SubscribeRequest request = BlockchainUpdates.SubscribeRequest.newBuilder()
        .setFromHeight(4200000)
        .build();

but I got this error:

Jun 04 17:25:17 ds1846 java[1661739]: io.grpc.StatusRuntimeException: CANCELLED: Failed to read message.
Jun 04 17:25:17 ds1846 java[1661739]:         at com.yusra.io.grpc.GrpcClient$1.onError(grpcclient.java:56)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(clientcalls.java:481)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.DelayedClientCall$DelayedListener$[3.run](https://3.run/)(delayedclientcall.java:489)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(delayedclientcall.java:453)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.DelayedClientCall$DelayedListener.onClose(delayedclientcall.java:486)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.ClientCallImpl.closeObserver(clientcallimpl.java:574)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.ClientCallImpl.access$300(clientcallimpl.java:72)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(clientcallimpl.java:742)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(clientcallimpl.java:723)
Jun 04 17:25:17 ds1846 java[1661739]:         at [io.grpc.internal.ContextRunnable.run](https://io.grpc.internal.contextrunnable.run/)(contextrunnable.java:37)
Jun 04 17:25:17 ds1846 java[1661739]:         at [io.grpc.internal.SerializingExecutor.run](https://io.grpc.internal.serializingexecutor.run/)(serializingexecutor.java:133)
Jun 04 17:25:17 ds1846 java[1661739]:         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
Jun 04 17:25:17 ds1846 java[1661739]:         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
Jun 04 17:25:17 ds1846 java[1661739]:         at java.base/java.lang.Thread.run(Thread.java:1583)
Jun 04 17:25:17 ds1846 java[1661739]: Caused by: io.grpc.StatusRuntimeException: INTERNAL: Invalid protobuf byte sequence
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.Status.asRuntimeException(status.java:525)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller.parse(protoliteutils.java:240)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller.parse(protoliteutils.java:134)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.MethodDescriptor.parseResponse(methoddescriptor.java:284)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(clientcallimpl.java:667)
Jun 04 17:25:17 ds1846 java[1661739]:         at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(clientcallimpl.java:654)
Jun 04 17:25:17 ds1846 java[1661739]:         ... 5 more
Jun 04 17:25:17 ds1846 java[1661739]: Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message had too many levels of nesting.  May be malicious.  Use CodedInputStream.setRecursionLimit() to increase the depth limit.

At the same time, everything worked correctly before, in the developer chat they told me that this was happening due to a node update

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.