Skip to content

Commit

Permalink
Merge branch 'master' into mc/proposer-fraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Cortesi committed Oct 3, 2019
2 parents 3057d5b + 21cbb94 commit 07c61d3
Show file tree
Hide file tree
Showing 159 changed files with 5,010 additions and 903 deletions.
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ coverage:
flags: protocol
threshold: 5%
target: 90%
if_no_uploads: error
if_not_found: success
if_ci_failed: error
patch:
default: off

Expand Down
4 changes: 2 additions & 2 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Before publishing a new celocli package, test in isolation using Docker. This co
```
# To test utils package, change $PWD/packages/cli to $PWD/packages/utils
# To test contractkit package, change $PWD/packages/contractkit to $PWD/packages/contractkit
celo-monorepo $ docker run -v $PWD/packages/cli:/tmp/npm_package -it --entrypoint bash node:8
celo-monorepo $ docker run -v $PWD/packages/cli:/tmp/npm_package -it --entrypoint bash node:10fn
root@e0d56700584f:/# mkdir /tmp/tmp1 && cd /tmp/tmp1
root@e0d56700584f:/tmp/tmp1# npm install /tmp/npm_package/
```
Expand Down Expand Up @@ -43,7 +43,7 @@ Once you publish do some manual tests, for example, after publishing `celocli`

```
# Docker for an isolated environment again
celo-monorepo $ docker run -it --entrypoint bash node:8
celo-monorepo $ docker run -it --entrypoint bash node:10
root@e0d56700584f:/# mkdir /tmp/tmp1 && cd /tmp/tmp1
root@e0d56700584f:/tmp/tmp1# npm install @celo/celocli@0.0.20
/tmp/tmp1# ./node_modules/.bin/celocli
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/attestation-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8
FROM node:10
WORKDIR /celo-monorepo

# ensure yarn.lock is evaluated by kaniko cache diff
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/celotool/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8
FROM node:10
WORKDIR /celo-monorepo

# Needed for gsutil
Expand Down
4 changes: 2 additions & 2 deletions dockerfiles/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ADD https://www.googleapis.com/storage/v1/b/genesis_blocks/o/${celo_env}?alt=med
ADD https://www.googleapis.com/storage/v1/b/static_nodes/o/${celo_env}?alt=media /celo/static-nodes.json

# Build Celocli
FROM node:8-alpine as node
FROM node:10-alpine as node

ARG celo_env

Expand All @@ -46,7 +46,7 @@ WORKDIR /celo-monorepo/
RUN npm install @celo/celocli

# Build the combined image
FROM node:8-alpine as final_image
FROM node:10-alpine as final_image

ARG network_name="alfajores"
ARG network_id="44782"
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/cloudbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8
FROM node:10

RUN apt-get update -y
RUN apt-get install lsb-release libudev-dev libusb-dev -y --no-install-recommends apt-utils
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/transaction-metrics-exporter/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8
FROM node:10
WORKDIR /celo-monorepo

# Needed for gsutil
Expand Down
4 changes: 2 additions & 2 deletions packages/attestation-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"lint": "tslint -c tslint.json --project ."
},
"dependencies": {
"@celo/contractkit": "0.1.1",
"@celo/utils": "^0.1.0",
"@celo/contractkit": "0.2.0-dev",
"@celo/utils": "0.1.2-dev",
"bignumber.js": "^7.2.0",
"body-parser": "1.19.0",
"debug": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/celotool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"license": "Apache-2.0",
"dependencies": {
"@celo/verification-pool-api": "^1.0.0",
"@celo/utils": "^0.1.0",
"@celo/utils": "0.1.2-dev",
"@celo/walletkit": "^0.0.14",
"@celo/contractkit": "0.1.6",
"@celo/contractkit": "0.2.0-dev",
"@google-cloud/monitoring": "0.7.1",
"@google-cloud/pubsub": "^0.28.1",
"@google-cloud/storage": "^2.4.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"test": "TZ=UTC jest"
},
"dependencies": {
"@celo/utils": "^0.1.0",
"@celo/contractkit": "^0.1.1",
"@celo/utils": "0.1.2-dev",
"@celo/contractkit": "0.2.0-dev",
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createAttestationServiceURLClaim } from '@celo/contractkit/lib/identity'
import { IArg } from '@oclif/parser/lib/args'
import { BaseCommand } from '../../base'
import { Args, Flags } from '../../utils/command'
import { modifyMetadata } from '../../utils/identity'

export default class ChangeAttestationServiceUrl extends BaseCommand {
static description = 'Change the URL of the attestation service in a local metadata file'

static flags = {
...BaseCommand.flags,
url: Flags.url({
required: true,
description: 'The url you want to claim',
}),
}

static args: IArg[] = [Args.file('file', { description: 'Path of the metadata file' })]

static examples = ['change-attestation-service-url ~/metadata.json']

async run() {
const res = this.parse(ChangeAttestationServiceUrl)
modifyMetadata(res.args.file, (metadata) => {
const claim = createAttestationServiceURLClaim(res.flags.url)
metadata.addClaim(claim)
})
}
}
30 changes: 30 additions & 0 deletions packages/cli/src/commands/identity/change-domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createDomainClaim } from '@celo/contractkit/lib/identity'
import { flags } from '@oclif/command'
import { IArg } from '@oclif/parser/lib/args'
import { BaseCommand } from '../../base'
import { Args } from '../../utils/command'
import { modifyMetadata } from '../../utils/identity'

export default class ChangeDomain extends BaseCommand {
static description = 'Change the domain in a local metadata file'

static flags = {
...BaseCommand.flags,
domain: flags.string({
required: true,
description: 'The domain you want to claim',
}),
}

static args: IArg[] = [Args.file('file', { description: 'Path of the metadata file' })]

static examples = ['change-domain ~/metadata.json']

async run() {
const res = this.parse(ChangeDomain)
modifyMetadata(res.args.file, (metadata) => {
const claim = createDomainClaim(res.flags.domain)
metadata.addClaim(claim)
})
}
}
30 changes: 30 additions & 0 deletions packages/cli/src/commands/identity/change-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createNameClaim } from '@celo/contractkit/lib/identity'
import { flags } from '@oclif/command'
import { IArg } from '@oclif/parser/lib/args'
import { BaseCommand } from '../../base'
import { Args } from '../../utils/command'
import { modifyMetadata } from '../../utils/identity'

export default class ChangeName extends BaseCommand {
static description = 'Change the name in a local metadata file'

static flags = {
...BaseCommand.flags,
name: flags.string({
required: true,
description: 'The name you want to claim',
}),
}

static args: IArg[] = [Args.file('file', { description: 'Path of the metadata file' })]

static examples = ['change-name ~/metadata.json']

async run() {
const res = this.parse(ChangeName)
modifyMetadata(res.args.file, (metadata) => {
const claim = createNameClaim(res.flags.name)
metadata.addClaim(claim)
})
}
}
25 changes: 25 additions & 0 deletions packages/cli/src/commands/identity/create-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IdentityMetadataWrapper } from '@celo/contractkit/lib/identity'
import { IArg } from '@oclif/parser/lib/args'
import { writeFileSync } from 'fs'
import { BaseCommand } from '../../base'
import { Args } from '../../utils/command'

export default class CreateMetadata extends BaseCommand {
static description = 'Create an empty metadata file'

static flags = {
...BaseCommand.flags,
}

static args: IArg[] = [
Args.newFile('file', { description: 'Path where the metadata should be saved' }),
]

static examples = ['create-metadata ~/metadata.json']

async run() {
const { args } = this.parse(CreateMetadata)
const metadata = new IdentityMetadataWrapper(IdentityMetadataWrapper.emptyData)
writeFileSync(args.file, metadata.toString())
}
}
23 changes: 3 additions & 20 deletions packages/cli/src/commands/identity/get-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ClaimTypes, IdentityMetadataWrapper } from '@celo/contractkit/lib/identity'
import { IdentityMetadataWrapper } from '@celo/contractkit/lib/identity'
import { IArg } from '@oclif/parser/lib/args'
import moment from 'moment'
import { BaseCommand } from '../../base'
import { Args } from '../../utils/command'
import { displayMetadata } from '../../utils/identity'

export default class GetMetadata extends BaseCommand {
static description = 'Show information about an address'
Expand All @@ -28,25 +28,8 @@ export default class GetMetadata extends BaseCommand {

try {
const metadata = await IdentityMetadataWrapper.fetchFromURL(metadataURL)

console.info('Metadata contains the following claims: \n')

metadata.claims.forEach((claim) => {
switch (claim.payload.type) {
case ClaimTypes.ATTESTATION_SERVICE_URL:
console.info(`Attestation Service Claim`)
console.info(`URL: ${claim.payload.url}`)
break
case ClaimTypes.NAME:
console.info(`Name Claim`)
console.info(`Name: "${claim.payload.name}"`)
break
default:
break
}

console.info(`(claim created ${moment.unix(claim.payload.timestamp).fromNow()})\n`)
})
displayMetadata(metadata)
} catch (error) {
console.error('Metadata could not be retrieved from ', metadataURL)
}
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/src/commands/identity/register-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { BaseCommand } from '../../base'
import { displaySendTx } from '../../utils/cli'
import { Flags } from '../../utils/command'

export default class RegisterMetadata extends BaseCommand {
static description = 'Register metadata about an address'

static flags = {
...BaseCommand.flags,
from: Flags.address({
required: true,
description: 'Addess of the account to set metadata for',
}),
url: Flags.url({
required: true,
description: 'The url to the metadata you want to register',
}),
}

static examples = ['register-metadata --url https://www.celo.org --from 0x0']

async run() {
const { flags } = this.parse(RegisterMetadata)
this.kit.defaultAccount = flags.from
const attestations = await this.kit.contracts.getAttestations()
await displaySendTx('registerMetadata', attestations.setMetadataURL(flags.url))
}
}
24 changes: 24 additions & 0 deletions packages/cli/src/commands/identity/show-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IdentityMetadataWrapper } from '@celo/contractkit/lib/identity'
import { IArg } from '@oclif/parser/lib/args'
import { BaseCommand } from '../../base'
import { Args } from '../../utils/command'
import { displayMetadata } from '../../utils/identity'

export default class ShowMetadata extends BaseCommand {
static description = 'Show the data in a local metadata file'

static flags = {
...BaseCommand.flags,
}

static args: IArg[] = [Args.file('file', { description: 'Path of the metadata file' })]

static examples = ['show-metadata ~/metadata.json']

async run() {
const res = this.parse(ShowMetadata)
const metadata = IdentityMetadataWrapper.fromFile(res.args.file)
console.info(`Metadata at ${res.args.file} contains the following claims: \n`)
displayMetadata(metadata)
}
}
31 changes: 31 additions & 0 deletions packages/cli/src/utils/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { flags } from '@oclif/command'
import { IArg, ParseFn } from '@oclif/parser/lib/args'
import { pathExistsSync } from 'fs-extra'
import Web3 from 'web3'
import { failWith } from './cli'

Expand All @@ -18,6 +19,28 @@ const parseAddress: ParseFn<string> = (input) => {
return failWith(`${input} is not a valid address`)
}
}

const parsePath: ParseFn<string> = (input) => {
if (pathExistsSync(input)) {
return input
} else {
return failWith(`File at "${input}" does not exist`)
}
}

// from http://urlregex.com/
const URL_REGEX = new RegExp(
/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/
)

const parseUrl: ParseFn<string> = (input) => {
if (URL_REGEX.test(input)) {
return input
} else {
return failWith(`"${input}" is not a valid URL`)
}
}

type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>
type ArgBuilder<T> = (name: string, args?: Partial<Omit<IArg<T>, 'name' | 'parse'>>) => IArg<T>
export function argBuilder<T>(parser: ParseFn<T>): ArgBuilder<T> {
Expand All @@ -40,8 +63,16 @@ export const Flags = {
description: 'Public Key',
helpValue: '0x',
}),
url: flags.build({
parse: parseUrl,
description: 'URL',
helpValue: 'htttps://www.celo.org',
}),
}

export const Args = {
address: argBuilder(parseAddress),
file: argBuilder(parsePath),
// TODO: Check that the file path is possible
newFile: argBuilder((x) => x),
}
Loading

0 comments on commit 07c61d3

Please sign in to comment.