Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,16 @@ end
- ~~Store the data from updateSigChainBlockHash and expose it through the library API~~ (Callback added)
- Write more tests!
- Declare type specifications on all functions
- Investigate how we can achieve better throughput with our GenStage
- Investigate how we can achieve better throughput with our GenStage

## Contribution

### Generate pb.ex files from proto

``` shell
protoc \
--proto_path=./deps/protobuf/src/ \
--proto_path=./lib/nkn_client/proto/ \
--elixir_out=./lib/nkn_client/proto/ \
./lib/nkn_client/proto/*.proto
```
1 change: 0 additions & 1 deletion lib/nkn_client/proto/messages.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule NknClient.Proto.Messages do
use Protobuf, from: Path.expand("messages.proto", __DIR__)
alias NknClient.Proto.Messages.OutboundMessage
alias NknClient.Proto.Messages.InboundMessage
alias NknClient.Proto.Messages.ClientMessage
Expand Down
101 changes: 101 additions & 0 deletions lib/nkn_client/proto/messages.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
defmodule NknClient.Proto.Messages.ClientMessageType do
@moduledoc false
use Protobuf, enum: true, syntax: :proto3

@type t :: integer | :OUTBOUND_MESSAGE | :INBOUND_MESSAGE | :RECEIPT

field :OUTBOUND_MESSAGE, 0
field :INBOUND_MESSAGE, 1
field :RECEIPT, 2
end

defmodule NknClient.Proto.Messages.CompressionType do
@moduledoc false
use Protobuf, enum: true, syntax: :proto3

@type t :: integer | :COMPRESSION_NONE | :COMPRESSION_ZLIB

field :COMPRESSION_NONE, 0
field :COMPRESSION_ZLIB, 1
end

defmodule NknClient.Proto.Messages.ClientMessage do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
message_type: NknClient.Proto.Messages.ClientMessageType.t(),
message: binary,
compression_type: NknClient.Proto.Messages.CompressionType.t()
}
defstruct [:message_type, :message, :compression_type]

field :message_type, 1, type: NknClient.Proto.Messages.ClientMessageType, enum: true
field :message, 2, type: :bytes
field :compression_type, 3, type: NknClient.Proto.Messages.CompressionType, enum: true
end

defmodule NknClient.Proto.Messages.OutboundMessage do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
dest: String.t(),
payload: binary,
dests: [String.t()],
max_holding_seconds: non_neg_integer,
nonce: non_neg_integer,
block_hash: binary,
signatures: [binary],
payloads: [binary]
}
defstruct [
:dest,
:payload,
:dests,
:max_holding_seconds,
:nonce,
:block_hash,
:signatures,
:payloads
]

field :dest, 1, type: :string
field :payload, 2, type: :bytes
field :dests, 3, repeated: true, type: :string
field :max_holding_seconds, 4, type: :uint32
field :nonce, 5, type: :uint32
field :block_hash, 6, type: :bytes
field :signatures, 7, repeated: true, type: :bytes
field :payloads, 8, repeated: true, type: :bytes
end

defmodule NknClient.Proto.Messages.InboundMessage do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
src: String.t(),
payload: binary,
prev_signature: binary
}
defstruct [:src, :payload, :prev_signature]

field :src, 1, type: :string
field :payload, 2, type: :bytes
field :prev_signature, 3, type: :bytes
end

defmodule NknClient.Proto.Messages.Receipt do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
prev_signature: binary,
signature: binary
}
defstruct [:prev_signature, :signature]

field :prev_signature, 1, type: :bytes
field :signature, 2, type: :bytes
end
3 changes: 3 additions & 0 deletions lib/nkn_client/proto/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ syntax = "proto3";

package messages;

import "elixir.proto";
option (elixir_module_prefix) = "NknClient.Proto.Messages";

enum ClientMessageType {
OUTBOUND_MESSAGE = 0;
INBOUND_MESSAGE = 1;
Expand Down
1 change: 0 additions & 1 deletion lib/nkn_client/proto/payloads.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule NknClient.Proto.Payloads do
use Protobuf, from: Path.expand("payloads.proto", __DIR__)
alias NknClient.Proto.Payloads.Message
alias NknClient.Proto.Payloads.Payload
alias NknClient.Proto.Payloads.TextData
Expand Down
61 changes: 61 additions & 0 deletions lib/nkn_client/proto/payloads.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
defmodule NknClient.Proto.Payloads.PayloadType do
@moduledoc false
use Protobuf, enum: true, syntax: :proto3

@type t :: integer | :BINARY | :TEXT | :ACK | :SESSION

field :BINARY, 0
field :TEXT, 1
field :ACK, 2
field :SESSION, 3
end

defmodule NknClient.Proto.Payloads.Message do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
payload: binary,
encrypted: boolean,
nonce: binary,
encrypted_key: binary
}
defstruct [:payload, :encrypted, :nonce, :encrypted_key]

field :payload, 1, type: :bytes
field :encrypted, 2, type: :bool
field :nonce, 3, type: :bytes
field :encrypted_key, 4, type: :bytes
end

defmodule NknClient.Proto.Payloads.Payload do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
type: NknClient.Proto.Payloads.PayloadType.t(),
message_id: binary,
data: binary,
reply_to_id: binary,
no_reply: boolean
}
defstruct [:type, :message_id, :data, :reply_to_id, :no_reply]

field :type, 1, type: NknClient.Proto.Payloads.PayloadType, enum: true
field :message_id, 2, type: :bytes
field :data, 3, type: :bytes
field :reply_to_id, 4, type: :bytes
field :no_reply, 5, type: :bool
end

defmodule NknClient.Proto.Payloads.TextData do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
text: String.t()
}
defstruct [:text]

field :text, 1, type: :string
end
3 changes: 3 additions & 0 deletions lib/nkn_client/proto/payloads.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ syntax = "proto3";

package payloads;

import "elixir.proto";
option (elixir_module_prefix) = "NknClient.Proto.Payloads";

enum PayloadType {
BINARY = 0;
TEXT = 1;
Expand Down
1 change: 0 additions & 1 deletion lib/nkn_client/proto/sigchain.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule NknClient.Proto.SigChain do
use Protobuf, from: Path.expand("sigchain.proto", __DIR__)
alias NknClient.Proto.SigChain.SigChainElem
alias NknClient.Proto.SigChain.SigChain

Expand Down
68 changes: 68 additions & 0 deletions lib/nkn_client/proto/sigchain.pb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
defmodule NknClient.Proto.SigChain.SigAlgo do
@moduledoc false
use Protobuf, enum: true, syntax: :proto3

@type t :: integer | :SIGNATURE | :VRF

field :SIGNATURE, 0
field :VRF, 1
end

defmodule NknClient.Proto.SigChain.SigChainElem do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
id: binary,
next_pubkey: binary,
mining: boolean,
signature: binary,
sig_algo: NknClient.Proto.SigChain.SigAlgo.t(),
vrf: binary,
proof: binary
}
defstruct [:id, :next_pubkey, :mining, :signature, :sig_algo, :vrf, :proof]

field :id, 1, type: :bytes
field :next_pubkey, 2, type: :bytes
field :mining, 3, type: :bool
field :signature, 4, type: :bytes
field :sig_algo, 5, type: NknClient.Proto.SigChain.SigAlgo, enum: true
field :vrf, 6, type: :bytes
field :proof, 7, type: :bytes
end

defmodule NknClient.Proto.SigChain.SigChain do
@moduledoc false
use Protobuf, syntax: :proto3

@type t :: %__MODULE__{
nonce: non_neg_integer,
data_size: non_neg_integer,
block_hash: binary,
src_id: binary,
src_pubkey: binary,
dest_id: binary,
dest_pubkey: binary,
elems: [NknClient.Proto.SigChain.SigChainElem.t()]
}
defstruct [
:nonce,
:data_size,
:block_hash,
:src_id,
:src_pubkey,
:dest_id,
:dest_pubkey,
:elems
]

field :nonce, 1, type: :uint32
field :data_size, 2, type: :uint32
field :block_hash, 3, type: :bytes
field :src_id, 4, type: :bytes
field :src_pubkey, 5, type: :bytes
field :dest_id, 6, type: :bytes
field :dest_pubkey, 7, type: :bytes
field :elems, 8, repeated: true, type: NknClient.Proto.SigChain.SigChainElem
end
3 changes: 3 additions & 0 deletions lib/nkn_client/proto/sigchain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ syntax = "proto3";

package sigchain;

import "elixir.proto";
option (elixir_module_prefix) = "NknClient.Proto.SigChain";

enum SigAlgo {
SIGNATURE = 0;
VRF = 1;
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ defmodule NknClient.MixProject do
{:hackney, "~> 1.7"},
{:websockex, "~> 0.4.0"},
{:gen_stage, "~> 0.14"},
{:exprotobuf, "~> 1.2"},
{:enacl, "~> 1.0"},
{:protobuf, "~> 0.7.1"},
{:google_protos, "~> 0.1", only: :dev},
{:ex_doc, "~> 0.18", only: :dev}
]
end
Expand Down