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

Commit

Permalink
Upgrade to Go 1.16
Browse files Browse the repository at this point in the history
Signed-off-by: Silas Davis <[email protected]>
  • Loading branch information
Silas Davis committed May 27, 2021
1 parent b6820f7 commit f4192e3
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 273 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
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
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
@@ -1,5 +1,5 @@
{
"version": "0.33.1-dev.e4b5f85b9",
"version": "0.33.1-dev.4b4d42399",
"name": "@hyperledger/burrow",
"description": "TypeScript library that calls a Hyperledger Burrow server over GRPC.",
"main": "./dist/index.js",
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';
}
File renamed without changes.
112 changes: 112 additions & 0 deletions js/src/contracts/compile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'fs';
import { ResolvedImport } from 'solc';
import solc from 'solc_v5';
import { ABI } from './abi';
import { Contract } from './contract';
Expand All @@ -10,6 +12,62 @@ export type CompiledContract = {
deployedBytecode?: string;
};

export namespace Solidity {
export type Bytecode = {
linkReferences: any;
object: string;
opcodes: string;
sourceMap: string;
};

export type Contract = {
assembly: any;
evm: {
bytecode: Bytecode;
deployedBytecode: Bytecode;
};
functionHashes: any;
gasEstimates: any;
abi: ABI.FunctionOrEvent[];
opcodes: string;
runtimeBytecode: string;
srcmap: string;
srcmapRuntime: string;
};

export type Source = {
AST: any;
};

export type InputDescription = {
language: string;
sources: Record<string, { content: string }>;
settings: {
outputSelection: Record<string, Record<string, Array<string>>>;
};
};

type Error = {
sourceLocation?: {
file: string;
start: number;
end: number;
};
type: string;
component: string;
severity: 'error' | 'warning';
message: string;
formattedMessage?: string;
};

export type OutputDescription = {
contracts: Record<string, Record<string, Contract>>;
errors: Array<Error>;
sourceList: Array<string>;
sources: Record<string, Source>;
};
}

// Compile solidity source code
export function compile<T = any>(
source: string,
Expand Down Expand Up @@ -45,3 +103,57 @@ function getCompiledCode(contract: solc.Contract): Required<CompiledContract> {
deployedBytecode: contract.evm.deployedBytecode.object,
};
}

function NewInputDescription(): Solidity.InputDescription {
return {
language: 'Solidity',
sources: {},
settings: { outputSelection: {} },
};
}

export function encodeInput(obj: Solidity.InputDescription): string {
return JSON.stringify(obj);
}

export function decodeOutput(str: string): Solidity.OutputDescription {
return JSON.parse(str);
}

export function inputDescriptionFromFiles(names: string[]): Solidity.InputDescription {
const desc = NewInputDescription();
names.map((name) => {
desc.sources[name] = { content: fs.readFileSync(name).toString() };
desc.settings.outputSelection[name] = {};
desc.settings.outputSelection[name]['*'] = ['*'];
});
return desc;
}

export function importLocal(path: string): ResolvedImport {
return {
contents: fs.readFileSync(path).toString(),
};
}

export function tokenizeLinks(links: Record<string, Record<string, unknown>>): string[] {
const libraries: Array<string> = [];
for (const file in links) {
for (const library in links[file]) {
libraries.push(file + ':' + library);
}
}
return libraries;
}

export function linker(bytecode: string, links: { name: string; address: string }[]): string {
for (const { name, address } of links) {
const paddedAddress = address + Array(40 - address.length + 1).join('0');
const truncated = name.slice(0, 36);
const label = '__' + truncated + Array(37 - truncated.length).join('_') + '__';
while (bytecode.indexOf(label) >= 0) {
bytecode = bytecode.replace(label, paddedAddress);
}
}
return bytecode;
}
3 changes: 2 additions & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export { Keccak } from 'sha3';
export * as Exec from '../proto/exec_pb';
export { CallTx, TxInput } from '../proto/payload_pb';
export { BlockRange } from '../proto/rpcevents_pb';
export { Client } from './client';
export { ContractCodec } from './codec';
export { Address } from './contracts/abi';
export { makeCallTx } from './contracts/call';
export { linker } from './contracts/compile';
export { Contract } from './contracts/contract';
export { Result } from './convert';
export {
Expand All @@ -21,4 +23,3 @@ export {
} from './events';
export { build } from './solts/build';
export { Caller, defaultCall, Provider } from './solts/interface.gd';
export { linker } from './solts/lib/compile';
6 changes: 3 additions & 3 deletions js/src/solts/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts, { factory } from 'typescript';
import { ABI } from './lib/abi';
import { ABI } from "../contracts/abi";
import { callerTypes, createCallerFunction } from './lib/caller';
import { declareContractType, generateContractObject } from './lib/contract';
import { generateDecodeObject } from './lib/decoder';
Expand All @@ -16,7 +16,7 @@ import { getContractMethods } from './lib/solidity';
import { declareConstant, ExportToken, importBurrow, importReadable } from './lib/syntax';
import Func = ABI.Func;

export { decodeOutput, encodeInput, importLocal, inputDescriptionFromFiles, tokenizeLinks } from './lib/compile';
export { decodeOutput, encodeInput, importLocal, inputDescriptionFromFiles, tokenizeLinks } from '../contracts/compile';

export type Compiled = {
name: string;
Expand Down Expand Up @@ -54,7 +54,7 @@ export function newFile(contracts: Compiled[], burrowImportPath: string): ts.Nod
const deployMembers = contract.bytecode
? [
declareConstant(bytecodeName, factory.createStringLiteral(contract.bytecode, true), true),
declareConstant(deployedBytecodeName, factory.createStringLiteral(contract.bytecode, true), true),
declareConstant(deployedBytecodeName, factory.createStringLiteral(contract.deployedBytecode, true), true),
generateDeployFunction(deploy, contract.links, provider, abiName, contractNames),
generateDeployContractFunction(deploy, contract.links, provider),
]
Expand Down
7 changes: 5 additions & 2 deletions js/src/solts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { promises as fs } from 'fs';
import * as path from 'path';
import * as solcv5 from 'solc_v5';
import * as solcv8 from 'solc_v8';
import { decodeOutput, encodeInput, importLocal, inputDescriptionFromFiles, Solidity } from '../contracts/compile';
import { Compiled, newFile, printNodes, tokenizeLinks } from './api';
import { decodeOutput, encodeInput, importLocal, inputDescriptionFromFiles, Solidity } from './lib/compile';

const solcCompilers = {
v5: solcv5,
Expand All @@ -29,7 +29,10 @@ export type BuildOptions = typeof defaultBuildOptions;
* - Outputs the ABI files into bin to be later included in the distribution (for Vent and other ABI-consuming services)
*/
export async function build(srcPathOrFiles: string | string[], opts?: Partial<BuildOptions>): Promise<void> {
const { solcVersion, binPath, basePath, burrowImportPath, abiExt } = { ...defaultBuildOptions, ...opts };
const { solcVersion, binPath, basePath, burrowImportPath, abiExt } = {
...defaultBuildOptions,
...opts,
};
const basePathPrefix = new RegExp(
'^' + path.resolve(basePath ?? (typeof srcPathOrFiles === 'string' ? srcPathOrFiles : process.cwd())),
);
Expand Down
31 changes: 0 additions & 31 deletions js/src/solts/lib/abi.ts

This file was deleted.

Loading

0 comments on commit f4192e3

Please sign in to comment.