Skip to content

Commit

Permalink
Merge pull request #3 from bandprotocol/patch-v0.43
Browse files Browse the repository at this point in the history
remove requestkey
  • Loading branch information
songwongtp authored Aug 24, 2021
2 parents ea8ee8d + a5fb3d2 commit 166c824
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 239 deletions.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf

proto-all: proto-format proto-lint proto-gen

proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace tendermintdev/sdk-proto-gen sh ./scripts/protocgen.sh

proto-format:
@echo "Formatting Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace \
--workdir /workspace tendermintdev/docker-build-proto \
find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;

proto-lint:
@$(DOCKER_BUF) lint --error-format=json

proto-check-breaking:
@$(DOCKER_BUF) check breaking --against-input $(HTTPS_GIT)#branch=master

.PHONY: proto-all proto-gen proto-gen-any proto-swagger-gen proto-format proto-lint proto-check-breaking
24 changes: 24 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: v1beta1

build:
roots:
- proto
- third_party/proto
lint:
use:
- DEFAULT
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
- UNARY_RPC
- COMMENT_FIELD
- SERVICE_SUFFIX
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
ignore:
- gogoproto
breaking:
use:
- FILE
ignore:
- gogoproto
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
module github.com/bandprotocol/bandchain-packet

go 1.15
go 1.16

require (
github.com/cosmos/cosmos-sdk v0.43.0
github.com/cosmos/ibc-go v1.0.0
github.com/gogo/protobuf v1.3.3
github.com/stretchr/testify v1.7.0
google.golang.org/protobuf v1.26.0
)

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
68 changes: 48 additions & 20 deletions go.sum

Large diffs are not rendered by default.

356 changes: 141 additions & 215 deletions packet/packet.pb.go

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions proto/oracle/v1/packet.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
syntax = "proto3";
package oracle.v1;

option go_package = "github.com/bandprotocol/bandchain-packet/packet";

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

// ResolveStatus encodes the status of an oracle request.
enum ResolveStatus {
option (gogoproto.goproto_enum_prefix) = false;

// Open - the request is not yet resolved.
RESOLVE_STATUS_OPEN_UNSPECIFIED = 0
[ (gogoproto.enumvalue_customname) = "RESOLVE_STATUS_OPEN" ];
// Success - the request has been resolved successfully with no errors.
RESOLVE_STATUS_SUCCESS = 1
[ (gogoproto.enumvalue_customname) = "RESOLVE_STATUS_SUCCESS" ];
// Failure - an error occured during the request's resolve call.
RESOLVE_STATUS_FAILURE = 2
[ (gogoproto.enumvalue_customname) = "RESOLVE_STATUS_FAILURE" ];
// Expired - the request does not get enough reports from validator within the
// timeframe.
RESOLVE_STATUS_EXPIRED = 3
[ (gogoproto.enumvalue_customname) = "RESOLVE_STATUS_EXPIRED" ];
}

// OracleRequestPacketData encodes an oracle request sent from other blockchains
// to BandChain.
message OracleRequestPacketData {
option (gogoproto.equal) = true;
// ClientID is the unique identifier of this oracle request, as specified by
// the client. This same unique ID will be sent back to the requester with the
// oracle response.
string client_id = 1 [ (gogoproto.customname) = "ClientID" ];
// OracleScriptID is the unique identifier of the oracle script to be
// executed.
uint64 oracle_script_id = 2 [ (gogoproto.customname) = "OracleScriptID" ];
// Calldata is the OBI-encoded calldata bytes available for oracle executor to
// read.
bytes calldata = 3;
// AskCount is the number of validators that are requested to respond to this
// oracle request. Higher value means more security, at a higher gas cost.
uint64 ask_count = 4;
// MinCount is the minimum number of validators necessary for the request to
// proceed to the execution phase. Higher value means more security, at the
// cost of liveness.
uint64 min_count = 5;
// FeeLimit is the maximum tokens that will be paid to all data source
// providers.
repeated cosmos.base.v1beta1.Coin fee_limit = 6 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
// PrepareGas is amount of gas to pay to prepare raw requests
uint64 prepare_gas = 7;
// ExecuteGas is amount of gas to reserve for executing
uint64 execute_gas = 8;
}

// OracleRequestPacketAcknowledgement encodes an oracle request acknowledgement
// send back to requester chain.
message OracleRequestPacketAcknowledgement {
option (gogoproto.equal) = true;
// RequestID is BandChain's unique identifier for this oracle request.
uint64 request_id = 1 [ (gogoproto.customname) = "RequestID" ];
}

// OracleResponsePacketData encodes an oracle response from BandChain to the
// requester.
message OracleResponsePacketData {
option (gogoproto.equal) = true;
// ClientID is the unique identifier matched with that of the oracle request
// packet.
string client_id = 1 [ (gogoproto.customname) = "ClientID" ];
// RequestID is BandChain's unique identifier for this oracle request.
uint64 request_id = 2 [ (gogoproto.customname) = "RequestID" ];
// AnsCount is the number of validators among to the asked validators that
// actually responded to this oracle request prior to this oracle request
// being resolved.
uint64 ans_count = 3;
// RequestTime is the UNIX epoch time at which the request was sent to
// BandChain.
int64 request_time = 4;
// ResolveTime is the UNIX epoch time at which the request was resolved to the
// final result.
int64 resolve_time = 5;
// ResolveStatus is the status of this oracle request, which can be OK,
// FAILURE, or EXPIRED.
ResolveStatus resolve_status = 6;
// Result is the final aggregated value encoded in OBI format. Only available
// if status if OK.
bytes result = 7;
}
43 changes: 43 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -eo pipefail

protoc_gen_gocosmos() {
if ! grep "github.com/gogo/protobuf => github.com/regen-network/protobuf" go.mod &>/dev/null ; then
echo -e "\tPlease run this command from somewhere inside the cosmos-sdk folder."
return 1
fi

go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest 2>/dev/null
}

protoc_gen_gocosmos

proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
buf protoc \
-I "proto" \
-I "third_party/proto" \
--gocosmos_out=plugins=interfacetype+grpc,\
Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
--grpc-gateway_out=logtostderr=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')

done

# command to generate docs using protoc-gen-doc
# buf protoc \
# -I "proto" \
# -I "third_party/proto" \
# --doc_out=./docs/core \
# --doc_opt=./docs/protodoc-markdown.tmpl,proto-docs.md \
# $(find "$(pwd)/proto" -maxdepth 5 -name '*.proto')
# go mod tidy

# # generate codec/testdata proto code
# buf protoc -I "proto" -I "third_party/proto" -I "testutil/testdata" --gocosmos_out=plugins=interfacetype+grpc,\
# Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. ./testutil/testdata/*.proto

# move proto files to the right places
cp -r github.com/bandprotocol/bandchain-packet/* ./
rm -rf github.com
40 changes: 40 additions & 0 deletions third_party/proto/cosmos/base/v1beta1/coin.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package cosmos.base.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/types";
option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.stringer_all) = false;

// Coin defines a token with a denomination and an amount.
//
// NOTE: The amount field is an Int which implements the custom method
// signatures required by gogoproto.
message Coin {
option (gogoproto.equal) = true;

string denom = 1;
string amount = 2 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false];
}

// DecCoin defines a token with a denomination and a decimal amount.
//
// NOTE: The amount field is an Dec which implements the custom method
// signatures required by gogoproto.
message DecCoin {
option (gogoproto.equal) = true;

string denom = 1;
string amount = 2 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false];
}

// IntProto defines a Protobuf wrapper around an Int object.
message IntProto {
string int = 1 [(gogoproto.customtype) = "Int", (gogoproto.nullable) = false];
}

// DecProto defines a Protobuf wrapper around a Dec object.
message DecProto {
string dec = 1 [(gogoproto.customtype) = "Dec", (gogoproto.nullable) = false];
}
145 changes: 145 additions & 0 deletions third_party/proto/gogoproto/gogo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Protocol Buffers for Go with Gadgets
//
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
// http://github.com/gogo/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto2";
package gogoproto;

import "google/protobuf/descriptor.proto";

option java_package = "com.google.protobuf";
option java_outer_classname = "GoGoProtos";
option go_package = "github.com/gogo/protobuf/gogoproto";

extend google.protobuf.EnumOptions {
optional bool goproto_enum_prefix = 62001;
optional bool goproto_enum_stringer = 62021;
optional bool enum_stringer = 62022;
optional string enum_customname = 62023;
optional bool enumdecl = 62024;
}

extend google.protobuf.EnumValueOptions {
optional string enumvalue_customname = 66001;
}

extend google.protobuf.FileOptions {
optional bool goproto_getters_all = 63001;
optional bool goproto_enum_prefix_all = 63002;
optional bool goproto_stringer_all = 63003;
optional bool verbose_equal_all = 63004;
optional bool face_all = 63005;
optional bool gostring_all = 63006;
optional bool populate_all = 63007;
optional bool stringer_all = 63008;
optional bool onlyone_all = 63009;

optional bool equal_all = 63013;
optional bool description_all = 63014;
optional bool testgen_all = 63015;
optional bool benchgen_all = 63016;
optional bool marshaler_all = 63017;
optional bool unmarshaler_all = 63018;
optional bool stable_marshaler_all = 63019;

optional bool sizer_all = 63020;

optional bool goproto_enum_stringer_all = 63021;
optional bool enum_stringer_all = 63022;

optional bool unsafe_marshaler_all = 63023;
optional bool unsafe_unmarshaler_all = 63024;

optional bool goproto_extensions_map_all = 63025;
optional bool goproto_unrecognized_all = 63026;
optional bool gogoproto_import = 63027;
optional bool protosizer_all = 63028;
optional bool compare_all = 63029;
optional bool typedecl_all = 63030;
optional bool enumdecl_all = 63031;

optional bool goproto_registration = 63032;
optional bool messagename_all = 63033;

optional bool goproto_sizecache_all = 63034;
optional bool goproto_unkeyed_all = 63035;
}

extend google.protobuf.MessageOptions {
optional bool goproto_getters = 64001;
optional bool goproto_stringer = 64003;
optional bool verbose_equal = 64004;
optional bool face = 64005;
optional bool gostring = 64006;
optional bool populate = 64007;
optional bool stringer = 67008;
optional bool onlyone = 64009;

optional bool equal = 64013;
optional bool description = 64014;
optional bool testgen = 64015;
optional bool benchgen = 64016;
optional bool marshaler = 64017;
optional bool unmarshaler = 64018;
optional bool stable_marshaler = 64019;

optional bool sizer = 64020;

optional bool unsafe_marshaler = 64023;
optional bool unsafe_unmarshaler = 64024;

optional bool goproto_extensions_map = 64025;
optional bool goproto_unrecognized = 64026;

optional bool protosizer = 64028;
optional bool compare = 64029;

optional bool typedecl = 64030;

optional bool messagename = 64033;

optional bool goproto_sizecache = 64034;
optional bool goproto_unkeyed = 64035;
}

extend google.protobuf.FieldOptions {
optional bool nullable = 65001;
optional bool embed = 65002;
optional string customtype = 65003;
optional string customname = 65004;
optional string jsontag = 65005;
optional string moretags = 65006;
optional string casttype = 65007;
optional string castkey = 65008;
optional string castvalue = 65009;

optional bool stdtime = 65010;
optional bool stdduration = 65011;
optional bool wktpointer = 65012;

optional string castrepeated = 65013;
}

0 comments on commit 166c824

Please sign in to comment.