Skip to content

Commit

Permalink
Create the initial project structure
Browse files Browse the repository at this point in the history
This commits the generated code, this should be removed at a later
date, to use it more dynamically or have a way to build it without
much issue.

This project can be ran from a REPL and submit some commands to a
listening Anoma Client.

The protobuf file is currently a WIP and should be refined
  • Loading branch information
mariari committed Oct 16, 2024
1 parent 47b17b4 commit 561ebb2
Show file tree
Hide file tree
Showing 10 changed files with 7,746 additions and 0 deletions.
25 changes: 25 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as announce_pb from './proto/anoma_pb';
import * as service from './proto/anoma_grpc_pb';
import * as grpc from '@grpc/grpc-js';


export function connect(address: string, port: number, creds?: grpc.ChannelCredentials)
: service.IntentsClient {
if (typeof creds == 'undefined') {
creds = grpc.credentials.createInsecure();
}
let target: string = address + ':' + port;
return new service.IntentsClient(target, creds)
}

function grpcfff(who: any) {
let target: string = 'localhost:50051';
var client = new service.IntentsClient(target, grpc.credentials.createInsecure());
var list = new announce_pb.IntentPool.ListIntents.Request();
var ret
let fun = (_err: any, response: announce_pb.IntentPool.ListIntents.Response) => { ret = response; };

client.listIntents(list, fun);

return ret;
}
1,606 changes: 1,606 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "anoma-client",
"version": "0.0.0",
"dependencies": {
"@grpc/grpc-js": "^1.12.0",
"google-protobuf": "^3.21.4",
"grpc-web": "^1.5.0",
"protoc-gen-grpc": "^2.0.4",
"protoc-gen-grpc-ts": "^1.0.1"
},
"devDependencies": {
"grpc_tools_node_protoc_ts": "^5.3.3"
}
}
148 changes: 148 additions & 0 deletions proto/anoma.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
syntax = "proto3";

package Anoma.Protobuf;

// ----------------- Announcement ---------------------

// The request message containing the user's name.
message Announcement {
NodeInfo node_info = 1;
repeated string engines = 2;
}

// ----------------- Node information -----------------

/*
This message contains all necessary information about a node
that sends a request.
*/

message NodeInfo {
bytes node_id = 1;
}

// ----------------- Prove -----------------------

message Prove {
message Request { string intent = 1; }

message Response { string result = 1; }
}
// ----------------- Intent Pool -----------------

message Intent { int32 value = 1; }
/*
Intent pool requests
*/
message IntentPool {
message AddIntent {
message Request { Intent intent = 1; }
message Response { string result = 1; }
}

message ListIntents {
message Request {}

message Response {
repeated string intents = 1; // a list of intents.
}
}
}

// ----------------- Indexer -----------------
message Indexer {
message Nullifiers {
message Request {}

message Response {
repeated string nullifiers = 1; // a list of intents.
}
}

message UnrevealedCommits {
message Request {}

message Response {
repeated string commits = 1; // a list of intents.
}
}

message UnspentResources {
message Request {}

message Response {
repeated string unspent_resources = 1; // a list of intents.
}
}
}

// ----------------- Mempool -----------------

/*
Intent pool requests
*/
message MemPool {
message Dump {
message Request {}

message Response {
repeated string dumps = 1; // a list of intents.
}
}
}

// ----------------- Intent Pool -----------------

/*
The envelope holds any message that can be sent or received by nodes.
The envelope is required because the encoder can only encode 1 type of message.
*/
message Envelope {
NodeInfo sender_info = 1; // node information of the sender.
bytes message_id = 2; // the message id.

oneof inner_message {
// announcement
Announcement announcement = 3;
// list intents
IntentPool.ListIntents.Request list_intents_request = 4;
IntentPool.ListIntents.Response list_intents_response = 5;

IntentPool.AddIntent.Request add_intent_request = 6;
IntentPool.AddIntent.Response add_intent_response = 7;

Indexer.Nullifiers.Request nullifiers_request = 8;
Indexer.Nullifiers.Response nullifiers_response = 9;

Indexer.UnrevealedCommits.Request unrevealed_commits_request = 10;
Indexer.UnrevealedCommits.Response unrevealed_commits_response = 11;

Indexer.UnspentResources.Request unspent_resources_request = 12;
Indexer.UnspentResources.Response unspent_resources_response = 13;

// mempool dump
MemPool.Dump.Request mempool_dump_request = 14;
MemPool.Dump.Response mempool_dump_response = 15;
}
}

// ----------------- Services -----------------
service Intents {
rpc ListIntents(IntentPool.ListIntents.Request)
returns (IntentPool.ListIntents.Response) {}

rpc AddIntent(IntentPool.AddIntent.Request)
returns (IntentPool.AddIntent.Response) {}

rpc ListNullifiers(Indexer.Nullifiers.Request)
returns (Indexer.Nullifiers.Response) {}

rpc ListUnrevealedCommits(Indexer.UnrevealedCommits.Request)
returns (Indexer.UnrevealedCommits.Response) {}

rpc ListUnspentResources(Indexer.UnspentResources.Request)
returns (Indexer.UnspentResources.Response) {}

rpc Prove(Prove.Request) returns (Prove.Response) {}
}
128 changes: 128 additions & 0 deletions proto/anoma_grpc_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// package: Anoma.Protobuf
// file: proto/anoma.proto

import * as grpc from '@grpc/grpc-js';
import * as proto_anoma_pb from '../proto/anoma_pb';

interface IIntentsService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
listIntents: IIntentsService_IListIntents;
addIntent: IIntentsService_IAddIntent;
listNullifiers: IIntentsService_IListNullifiers;
listUnrevealedCommits: IIntentsService_IListUnrevealedCommits;
listUnspentResources: IIntentsService_IListUnspentResources;
prove: IIntentsService_IProve;
}

interface IIntentsService_IListIntents extends grpc.MethodDefinition<proto_anoma_pb.IntentPool.ListIntents.Request, proto_anoma_pb.IntentPool.ListIntents.Response> {
path: '/Anoma.Protobuf.Intents/ListIntents'
requestStream: false
responseStream: false
requestSerialize: grpc.serialize<proto_anoma_pb.IntentPool.ListIntents.Request>;
requestDeserialize: grpc.deserialize<proto_anoma_pb.IntentPool.ListIntents.Request>;
responseSerialize: grpc.serialize<proto_anoma_pb.IntentPool.ListIntents.Response>;
responseDeserialize: grpc.deserialize<proto_anoma_pb.IntentPool.ListIntents.Response>;
}

interface IIntentsService_IAddIntent extends grpc.MethodDefinition<proto_anoma_pb.IntentPool.AddIntent.Request, proto_anoma_pb.IntentPool.AddIntent.Response> {
path: '/Anoma.Protobuf.Intents/AddIntent'
requestStream: false
responseStream: false
requestSerialize: grpc.serialize<proto_anoma_pb.IntentPool.AddIntent.Request>;
requestDeserialize: grpc.deserialize<proto_anoma_pb.IntentPool.AddIntent.Request>;
responseSerialize: grpc.serialize<proto_anoma_pb.IntentPool.AddIntent.Response>;
responseDeserialize: grpc.deserialize<proto_anoma_pb.IntentPool.AddIntent.Response>;
}

interface IIntentsService_IListNullifiers extends grpc.MethodDefinition<proto_anoma_pb.Indexer.Nullifiers.Request, proto_anoma_pb.Indexer.Nullifiers.Response> {
path: '/Anoma.Protobuf.Intents/ListNullifiers'
requestStream: false
responseStream: false
requestSerialize: grpc.serialize<proto_anoma_pb.Indexer.Nullifiers.Request>;
requestDeserialize: grpc.deserialize<proto_anoma_pb.Indexer.Nullifiers.Request>;
responseSerialize: grpc.serialize<proto_anoma_pb.Indexer.Nullifiers.Response>;
responseDeserialize: grpc.deserialize<proto_anoma_pb.Indexer.Nullifiers.Response>;
}

interface IIntentsService_IListUnrevealedCommits extends grpc.MethodDefinition<proto_anoma_pb.Indexer.UnrevealedCommits.Request, proto_anoma_pb.Indexer.UnrevealedCommits.Response> {
path: '/Anoma.Protobuf.Intents/ListUnrevealedCommits'
requestStream: false
responseStream: false
requestSerialize: grpc.serialize<proto_anoma_pb.Indexer.UnrevealedCommits.Request>;
requestDeserialize: grpc.deserialize<proto_anoma_pb.Indexer.UnrevealedCommits.Request>;
responseSerialize: grpc.serialize<proto_anoma_pb.Indexer.UnrevealedCommits.Response>;
responseDeserialize: grpc.deserialize<proto_anoma_pb.Indexer.UnrevealedCommits.Response>;
}

interface IIntentsService_IListUnspentResources extends grpc.MethodDefinition<proto_anoma_pb.Indexer.UnspentResources.Request, proto_anoma_pb.Indexer.UnspentResources.Response> {
path: '/Anoma.Protobuf.Intents/ListUnspentResources'
requestStream: false
responseStream: false
requestSerialize: grpc.serialize<proto_anoma_pb.Indexer.UnspentResources.Request>;
requestDeserialize: grpc.deserialize<proto_anoma_pb.Indexer.UnspentResources.Request>;
responseSerialize: grpc.serialize<proto_anoma_pb.Indexer.UnspentResources.Response>;
responseDeserialize: grpc.deserialize<proto_anoma_pb.Indexer.UnspentResources.Response>;
}

interface IIntentsService_IProve extends grpc.MethodDefinition<proto_anoma_pb.Prove.Request, proto_anoma_pb.Prove.Response> {
path: '/Anoma.Protobuf.Intents/Prove'
requestStream: false
responseStream: false
requestSerialize: grpc.serialize<proto_anoma_pb.Prove.Request>;
requestDeserialize: grpc.deserialize<proto_anoma_pb.Prove.Request>;
responseSerialize: grpc.serialize<proto_anoma_pb.Prove.Response>;
responseDeserialize: grpc.deserialize<proto_anoma_pb.Prove.Response>;
}

export const IntentsService: IIntentsService;
export interface IIntentsServer extends grpc.UntypedServiceImplementation {
listIntents: grpc.handleUnaryCall<proto_anoma_pb.IntentPool.ListIntents.Request, proto_anoma_pb.IntentPool.ListIntents.Response>;
addIntent: grpc.handleUnaryCall<proto_anoma_pb.IntentPool.AddIntent.Request, proto_anoma_pb.IntentPool.AddIntent.Response>;
listNullifiers: grpc.handleUnaryCall<proto_anoma_pb.Indexer.Nullifiers.Request, proto_anoma_pb.Indexer.Nullifiers.Response>;
listUnrevealedCommits: grpc.handleUnaryCall<proto_anoma_pb.Indexer.UnrevealedCommits.Request, proto_anoma_pb.Indexer.UnrevealedCommits.Response>;
listUnspentResources: grpc.handleUnaryCall<proto_anoma_pb.Indexer.UnspentResources.Request, proto_anoma_pb.Indexer.UnspentResources.Response>;
prove: grpc.handleUnaryCall<proto_anoma_pb.Prove.Request, proto_anoma_pb.Prove.Response>;
}

export interface IIntentsClient {
listIntents(request: proto_anoma_pb.IntentPool.ListIntents.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.ListIntents.Response) => void): grpc.ClientUnaryCall;
listIntents(request: proto_anoma_pb.IntentPool.ListIntents.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.ListIntents.Response) => void): grpc.ClientUnaryCall;
listIntents(request: proto_anoma_pb.IntentPool.ListIntents.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.ListIntents.Response) => void): grpc.ClientUnaryCall;
addIntent(request: proto_anoma_pb.IntentPool.AddIntent.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.AddIntent.Response) => void): grpc.ClientUnaryCall;
addIntent(request: proto_anoma_pb.IntentPool.AddIntent.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.AddIntent.Response) => void): grpc.ClientUnaryCall;
addIntent(request: proto_anoma_pb.IntentPool.AddIntent.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.AddIntent.Response) => void): grpc.ClientUnaryCall;
listNullifiers(request: proto_anoma_pb.Indexer.Nullifiers.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.Nullifiers.Response) => void): grpc.ClientUnaryCall;
listNullifiers(request: proto_anoma_pb.Indexer.Nullifiers.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.Nullifiers.Response) => void): grpc.ClientUnaryCall;
listNullifiers(request: proto_anoma_pb.Indexer.Nullifiers.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.Nullifiers.Response) => void): grpc.ClientUnaryCall;
listUnrevealedCommits(request: proto_anoma_pb.Indexer.UnrevealedCommits.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnrevealedCommits.Response) => void): grpc.ClientUnaryCall;
listUnrevealedCommits(request: proto_anoma_pb.Indexer.UnrevealedCommits.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnrevealedCommits.Response) => void): grpc.ClientUnaryCall;
listUnrevealedCommits(request: proto_anoma_pb.Indexer.UnrevealedCommits.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnrevealedCommits.Response) => void): grpc.ClientUnaryCall;
listUnspentResources(request: proto_anoma_pb.Indexer.UnspentResources.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnspentResources.Response) => void): grpc.ClientUnaryCall;
listUnspentResources(request: proto_anoma_pb.Indexer.UnspentResources.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnspentResources.Response) => void): grpc.ClientUnaryCall;
listUnspentResources(request: proto_anoma_pb.Indexer.UnspentResources.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnspentResources.Response) => void): grpc.ClientUnaryCall;
prove(request: proto_anoma_pb.Prove.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Prove.Response) => void): grpc.ClientUnaryCall;
prove(request: proto_anoma_pb.Prove.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Prove.Response) => void): grpc.ClientUnaryCall;
prove(request: proto_anoma_pb.Prove.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Prove.Response) => void): grpc.ClientUnaryCall;
}

export class IntentsClient extends grpc.Client implements IIntentsClient {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ClientOptions>);
public listIntents(request: proto_anoma_pb.IntentPool.ListIntents.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.ListIntents.Response) => void): grpc.ClientUnaryCall;
public listIntents(request: proto_anoma_pb.IntentPool.ListIntents.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.ListIntents.Response) => void): grpc.ClientUnaryCall;
public listIntents(request: proto_anoma_pb.IntentPool.ListIntents.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.ListIntents.Response) => void): grpc.ClientUnaryCall;
public addIntent(request: proto_anoma_pb.IntentPool.AddIntent.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.AddIntent.Response) => void): grpc.ClientUnaryCall;
public addIntent(request: proto_anoma_pb.IntentPool.AddIntent.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.AddIntent.Response) => void): grpc.ClientUnaryCall;
public addIntent(request: proto_anoma_pb.IntentPool.AddIntent.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.IntentPool.AddIntent.Response) => void): grpc.ClientUnaryCall;
public listNullifiers(request: proto_anoma_pb.Indexer.Nullifiers.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.Nullifiers.Response) => void): grpc.ClientUnaryCall;
public listNullifiers(request: proto_anoma_pb.Indexer.Nullifiers.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.Nullifiers.Response) => void): grpc.ClientUnaryCall;
public listNullifiers(request: proto_anoma_pb.Indexer.Nullifiers.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.Nullifiers.Response) => void): grpc.ClientUnaryCall;
public listUnrevealedCommits(request: proto_anoma_pb.Indexer.UnrevealedCommits.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnrevealedCommits.Response) => void): grpc.ClientUnaryCall;
public listUnrevealedCommits(request: proto_anoma_pb.Indexer.UnrevealedCommits.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnrevealedCommits.Response) => void): grpc.ClientUnaryCall;
public listUnrevealedCommits(request: proto_anoma_pb.Indexer.UnrevealedCommits.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnrevealedCommits.Response) => void): grpc.ClientUnaryCall;
public listUnspentResources(request: proto_anoma_pb.Indexer.UnspentResources.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnspentResources.Response) => void): grpc.ClientUnaryCall;
public listUnspentResources(request: proto_anoma_pb.Indexer.UnspentResources.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnspentResources.Response) => void): grpc.ClientUnaryCall;
public listUnspentResources(request: proto_anoma_pb.Indexer.UnspentResources.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Indexer.UnspentResources.Response) => void): grpc.ClientUnaryCall;
public prove(request: proto_anoma_pb.Prove.Request, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Prove.Response) => void): grpc.ClientUnaryCall;
public prove(request: proto_anoma_pb.Prove.Request, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Prove.Response) => void): grpc.ClientUnaryCall;
public prove(request: proto_anoma_pb.Prove.Request, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: proto_anoma_pb.Prove.Response) => void): grpc.ClientUnaryCall;
}

Loading

0 comments on commit 561ebb2

Please sign in to comment.