Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1491 from hyperledger/solts
Browse files Browse the repository at this point in the history
Fix collisions in ABI output, submit contract metadata on deploy, remove GRPC dependencies from codegen interface.gd.ts
  • Loading branch information
Casey Kuhlman authored May 28, 2021
2 parents 89c3124 + e87138a commit 56cf347
Show file tree
Hide file tree
Showing 49 changed files with 1,058 additions and 1,132 deletions.
10 changes: 5 additions & 5 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.15-alpine3.13
FROM golang:1.16-alpine3.13
MAINTAINER Monax <[email protected]>

ENV DOCKER_VERSION "17.12.1-ce"
ENV GORELEASER_VERSION "v0.104.1"
ENV DOCKER_VERSION "20.10.6"
ENV GORELEASER_VERSION "v0.166.1"
# This is the image used by the Circle CI config
# Update remote with 'make push_ci_image'
RUN apk add --update --no-cache \
Expand All @@ -22,8 +22,8 @@ RUN apk add --update --no-cache \
libffi-dev \
openssl-dev \
python3-dev \
py-pip
RUN pip3 install docker-compose
py-pip \
docker-compose
# get docker client
WORKDIR /usr/bin
RUN curl -sS -L https://download.docker.com/linux/static/stable/x86_64/docker-$DOCKER_VERSION.tgz | tar xz --strip-components 1 docker/docker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
id: go
- uses: actions/checkout@v2
- run: make test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- run: git fetch --prune --unshallow
- uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
- uses: goreleaser/goreleaser-action@v1
with:
version: latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
id: go
- uses: actions/checkout@v2
- run: git fetch --unshallow --prune
Expand All @@ -27,7 +27,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: 1.15
go-version: 1.16
id: go
- uses: actions/checkout@v1
- run: make test_integration
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# [Hyperledger Burrow](https://github.com/hyperledger/burrow) Changelog
## [0.34.0] - 2021-05-28
### Changed
- [JS] Provider interface no longer depends on GRPC types to improve compatibility between versions of Burrow.js and ease of extension
- [JS] Use non-unique marker interface to indicate stream cancellation in event reducer (again for compatibility between versions and extensibility)
- [Go] Upgrade to Go 1.16

### Fixed
- [JS] Fix codegen silently swallowing collisions of abi files (renamed from .bin to .abi) and use hierarchical directory structure to further reduce chance of collision
- [JS] Just depende on @ethersproject/abi rather than entire umbrella project

### Added
- [JS] Include deployedBycode and optionally submit ABI's to Burrow's contract metadata store on deploy


## [0.33.1] - 2021-05-24
### Fixed
- [JS] Return bytesNN as Buffer to agree with typings
Expand Down Expand Up @@ -775,6 +789,7 @@ This release marks the start of Eris-DB as the full permissioned blockchain node
- [Blockchain] Fix getBlocks to respect block height cap.


[0.34.0]: https://github.com/hyperledger/burrow/compare/v0.33.1...v0.34.0
[0.33.1]: https://github.com/hyperledger/burrow/compare/v0.33.0...v0.33.1
[0.33.0]: https://github.com/hyperledger/burrow/compare/v0.32.1...v0.33.0
[0.32.1]: https://github.com/hyperledger/burrow/compare/v0.32.0...v0.32.1
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For solc binary
FROM ethereum/solc:0.5.12 as solc-builder
FROM ethereum/solc:0.5.15 as solc-builder
# We use a multistage build to avoid bloating our deployment image with build dependencies
FROM golang:1.15-alpine3.12 as builder
FROM golang:1.16-alpine3.13 as builder

RUN apk add --no-cache --update git bash make musl-dev gcc libc6-compat

Expand All @@ -13,7 +13,7 @@ WORKDIR $REPO
RUN make build

# This will be our base container image
FROM alpine:3.11
FROM alpine:3.13

# Variable arguments to populate labels
ARG USER=burrow
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ REPO := $(shell pwd)

# Our own Go files containing the compiled bytecode of solidity files as a constant

export CI_IMAGE=hyperledger/burrow:ci-2
export CI_IMAGE=hyperledger/burrow:ci-3

VERSION := $(shell scripts/version.sh)
# Gets implicit default GOPATH if not set
Expand Down
10 changes: 8 additions & 2 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
### Changed
- [JS] Provider interface no longer depends on GRPC types to improve compatibility between versions of Burrow.js and ease of extension
- [JS] Use non-unique marker interface to indicate stream cancellation in event reducer (again for compatibility between versions and extensibility)
- [Go] Upgrade to Go 1.16

### Fixed
- [JS] Return bytesNN as Buffer to agree with typings
- [JS] Fix codegen silently swallowing collisions of abi files (renamed from .bin to .abi) and use hierarchical directory structure to further reduce chance of collision
- [JS] Just depende on @ethersproject/abi rather than entire umbrella project

### Added
- [JS] Inline sources and source maps
- [JS] Include deployedBycode and optionally submit ABI's to Burrow's contract metadata store on deploy

4 changes: 2 additions & 2 deletions execution/evm/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func LoadPath(abiFileOrDirs ...string) (*Spec, error) {
specs := make([]*Spec, 0)

for _, dir := range abiFileOrDirs {
err := filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
err := filepath.WalkDir(dir, func(path string, dir os.DirEntry, err error) error {
if err != nil {
return fmt.Errorf("error returned while walking abiDir '%s': %v", dir, err)
}
ext := filepath.Ext(path)
if fi.IsDir() || !(ext == ".bin" || ext == ".abi" || ext == ".json") {
if dir.IsDir() || !(ext == ".bin" || ext == ".abi" || ext == ".json") {
return nil
}
abiSpc, err := ReadSpecFile(path)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hyperledger/burrow

go 1.15
go 1.16

require (
github.com/BurntSushi/toml v0.3.1
Expand Down Expand Up @@ -52,7 +52,7 @@ require (
github.com/xlab/treeprint v1.0.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.35.0
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@grpc/grpc-js": "^1.3.0",
"ethers": "^5.1.4",
"@ethersproject/abi": "^5.2.0",
"google-protobuf": "^3.15.8",
"sha3": "^2.1.4",
"solc_v5": "npm:solc@^0.5.17",
Expand Down
37 changes: 22 additions & 15 deletions js/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Interface } from '@ethersproject/abi';
import * as grpc from '@grpc/grpc-js';
import { Interface } from 'ethers/lib/utils';
import { Event, TxExecution } from '../proto/exec_pb';
import { CallTx, ContractMeta } from '../proto/payload_pb';
import { TxExecution } from '../proto/exec_pb';
import { CallTx } from '../proto/payload_pb';
import { ExecutionEventsClient, IExecutionEventsClient } from '../proto/rpcevents_grpc_pb';
import { IQueryClient, QueryClient } from '../proto/rpcquery_grpc_pb';
import { GetMetadataParam, StatusParam } from '../proto/rpcquery_pb';
import { ITransactClient, TransactClient } from '../proto/rpctransact_grpc_pb';
import { ResultStatus } from '../proto/rpc_pb';
import { ContractCodec, getContractCodec } from './codec';
import { Address } from './contracts/abi';
import { makeCallTx } from './contracts/call';
import { getContractMeta, makeCallTx } from './contracts/call';
import { CallOptions, Contract, ContractInstance } from './contracts/contract';
import { toBuffer } from './convert';
import { getException } from './error';
import { Bounds, EventCallback, EventStream, getBlockRange, queryFor, stream } from './events';
import { Bounds, Event, EventCallback, EventStream, getBlockRange, queryFor, stream } from './events';
import { Namereg } from './namereg';
import { Provider } from './solts/interface.gd';

Expand Down Expand Up @@ -125,22 +125,33 @@ export class Client implements Provider {
// Methods below implement the generated codegen provider
// TODO: should probably generate canonical version of Provider interface somewhere outside of files

async deploy(msg: CallTx): Promise<Address> {
const txe = await this.callTxSync(msg);
async deploy(
data: string | Uint8Array,
contractMeta: { abi: string; codeHash: Uint8Array }[] = [],
): Promise<Address> {
const tx = makeCallTx(
toBuffer(data),
this.account,
undefined,
contractMeta.map(({ abi, codeHash }) => getContractMeta(abi, codeHash)),
);
const txe = await this.callTxSync(tx);
const contractAddress = txe.getReceipt()?.getContractaddress_asU8();
if (!contractAddress) {
throw new Error(`deploy appears to have succeeded but contract address is missing from result: ${txe}`);
}
return Buffer.from(contractAddress).toString('hex').toUpperCase();
}

async call(msg: CallTx): Promise<Uint8Array | undefined> {
const txe = await this.callTxSync(msg);
async call(data: string | Uint8Array, address: string): Promise<Uint8Array | undefined> {
const tx = makeCallTx(toBuffer(data), this.account, address);
const txe = await this.callTxSync(tx);
return txe.getResult()?.getReturn_asU8();
}

async callSim(msg: CallTx): Promise<Uint8Array | undefined> {
const txe = await this.callTxSim(msg);
async callSim(data: string | Uint8Array, address: string): Promise<Uint8Array | undefined> {
const tx = makeCallTx(toBuffer(data), this.account, address);
const txe = await this.callTxSim(tx);
return txe.getResult()?.getReturn_asU8();
}

Expand All @@ -154,10 +165,6 @@ export class Client implements Provider {
return stream(this.executionEvents, getBlockRange(start, end), queryFor({ address, signatures }), callback);
}

payload(data: string | Uint8Array, address?: string, contractMeta: ContractMeta[] = []): CallTx {
return makeCallTx(typeof data === 'string' ? toBuffer(data) : data, this.account, address, contractMeta);
}

contractCodec(contractABI: string): ContractCodec {
const iface = new Interface(contractABI);
return getContractCodec(iface);
Expand Down
2 changes: 1 addition & 1 deletion js/src/codec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventFragment, Fragment, FunctionFragment, Interface } from 'ethers/lib/utils';
import { EventFragment, Fragment, FunctionFragment, Interface } from '@ethersproject/abi';
import { postDecodeResult, preEncodeResult, prefixedHexString, toBuffer } from './convert';

export type ContractCodec = {
Expand Down
47 changes: 31 additions & 16 deletions js/src/contracts/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,37 @@ export type Address = string;

export type FunctionIO = FunctionInput & FunctionOutput;

// TODO: replace with ethers js
export namespace ABI {
export type Func = {
type: 'function' | 'constructor' | 'fallback';
name: string;
inputs?: Array<FunctionInput>;
outputs?: Array<FunctionOutput>;
stateMutability: 'pure' | 'view' | 'nonpayable' | 'payable';
payable?: boolean;
constant?: boolean;
};

export type Event = {
type: 'event';
name: string;
inputs: Array<EventInput>;
anonymous: boolean;
};

export type FunctionInput = {
name: string;
type: string;
components?: FunctionInput[];
internalType?: string;
};

export type FunctionOutput = FunctionInput;
export type EventInput = FunctionInput & { indexed?: boolean };

export type FunctionIO = FunctionInput & FunctionOutput;
export type FunctionOrEvent = Func | Event;
}

export function transformToFullName(abi: SolidityFunction | Event): string {
if (abi.name.indexOf('(') !== -1) {
Expand All @@ -15,18 +45,3 @@ export function transformToFullName(abi: SolidityFunction | Event): string {
const typeName = (abi.inputs as Array<EventInput | FunctionIO>).map((i) => i.type).join(',');
return abi.name + '(' + typeName + ')';
}

export function extractDisplayName(name: string): string {
const length = name.indexOf('(');
return length !== -1 ? name.substr(0, length) : name;
}

export function extractTypeName(name: string): string {
/// TODO: make it invulnerable
const length = name.indexOf('(');
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : '';
}

export function isFunction(abi: SolidityFunction | Event): abi is SolidityFunction {
return abi.type === 'function' || abi.type === 'constructor';
}
23 changes: 19 additions & 4 deletions js/src/contracts/call.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { AbiCoder, FunctionFragment, Interface, Result as DecodedResult } from '@ethersproject/abi';
import * as grpc from '@grpc/grpc-js';
import { Metadata } from '@grpc/grpc-js';
import { callErrorFromStatus } from '@grpc/grpc-js/build/src/call';
import { AbiCoder, FunctionFragment, Interface, Result as DecodedResult } from 'ethers/lib/utils';
import { Keccak } from 'sha3';
import { SolidityFunction } from 'solc';
import { Result } from '../../proto/exec_pb';
import { CallTx, ContractMeta, TxInput } from '../../proto/payload_pb';
import { Envelope } from '../../proto/txs_pb';
import { Pipe } from '../client';
import { postDecodeResult, preEncodeResult, toBuffer } from '../convert';
import { Address } from './abi';
import { ABI, Address } from './abi';
import { CallOptions } from './contract';

export const DEFAULT_GAS = 1111111111;

export { Result as DecodeResult } from 'ethers/lib/utils';

const WasmMagic = Buffer.from('\0asm');

const coder = new AbiCoder();
Expand Down Expand Up @@ -48,6 +47,22 @@ export function makeCallTx(
return payload;
}

export function getContractMetaFromBytecode(abi: ABI, deployedBytecode: string): ContractMeta {
const hasher = new Keccak(256);
const codeHash = hasher.update(deployedBytecode, 'hex').digest();
return getContractMeta(abi, codeHash);
}

export function getContractMeta(abi: ABI | string, codeHash: Uint8Array): ContractMeta {
const meta = new ContractMeta();
if (typeof abi !== 'string') {
abi = JSON.stringify({ Abi: abi });
}
meta.setMeta(abi);
meta.setCodehash(codeHash);
return meta;
}

export type TransactionResult = {
contractAddress: string;
height: number;
Expand Down
File renamed without changes.
Loading

0 comments on commit 56cf347

Please sign in to comment.