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
133 changes: 25 additions & 108 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,29 @@
# Makefile for building target binaries.
#

# Configuration
BUILD_ROOT = $(abspath ./)
BIN_DIR = ./bin
LINUX_BIN_DIR = ./build/linux

GOBUILD = go build
GOBUILD_TAGS =
# GOBUILD_ENVS = CGO_ENABLED=0
GOBUILD_LDFLAGS =
GOBUILD_FLAGS = -tags "$(GOBUILD_TAGS)" -ldflags "$(GOBUILD_LDFLAGS)"
GOBUILD_ENVS_LINUX = $(GOBUILD_ENVS) GOOS=linux GOARCH=amd64

GOTEST = go test
GOTEST_FLAGS = -test.short

# Build flags
GL_VERSION ?= $(shell git describe --always --tags --dirty)
GL_TAG ?= latest
BUILD_INFO = $(shell go env GOOS)/$(shell go env GOARCH) tags($(GOBUILD_TAGS))-$(shell date '+%Y-%m-%d-%H:%M:%S')

#
# Build scripts for command binaries.
#
CMDS = $(patsubst cmd/%,%,$(wildcard cmd/*))
.PHONY: $(CMDS) $(addsuffix -linux,$(CMDS))
define CMD_template
$(BIN_DIR)/$(1) $(1) : GOBUILD_LDFLAGS+=$$($(1)_LDFLAGS)
$(BIN_DIR)/$(1) $(1) :
@ \
rm -f $(BIN_DIR)/$(1) ; \
echo "[#] go build ./cmd/$(1)"
$$(GOBUILD_ENVS) \
go build $$(GOBUILD_FLAGS) \
-o $(BIN_DIR)/$(1) ./cmd/$(1)

$(LINUX_BIN_DIR)/$(1) $(1)-linux : GOBUILD_LDFLAGS+=$$($(1)_LDFLAGS)
$(LINUX_BIN_DIR)/$(1) $(1)-linux :
@ \
rm -f $(LINUX_BIN_DIR)/$(1) ; \
echo "[#] go build ./cmd/$(1)"
$$(GOBUILD_ENVS_LINUX) \
go build $$(GOBUILD_FLAGS) \
-o $(LINUX_BIN_DIR)/$(1) ./cmd/$(1)
endef
$(foreach M,$(CMDS),$(eval $(call CMD_template,$(M))))

# Build flags for each command
iconbridge_LDFLAGS = -X 'main.version=$(GL_VERSION)' -X 'main.build=$(BUILD_INFO)'
BUILD_TARGETS += iconbridge

linux : $(addsuffix -linux,$(BUILD_TARGETS))

SOLIDITY_DIST_DIR = $(BUILD_ROOT)/build/contracts/solidity

$(SOLIDITY_DIST_DIR)/%:
$(eval MODULE := $(patsubst $(SOLIDITY_DIST_DIR)/%,%,$@))
mkdir -p $@/contracts ; \
mkdir -p $@/migrations ; \
cp -r solidity/$(MODULE)/contracts/* $@/contracts ; \
cp -r solidity/$(MODULE)/migrations/* $@/migrations ; \
cp solidity/$(MODULE)/{truffle-config.js,*.json,*.lock} $@/ ; \
cp solidity/$(MODULE)/truffle-config.js $@/ ; \
cp solidity/$(MODULE)/*.json $@/ ; \
cp solidity/$(MODULE)/*.lock $@/ ; \
rm -rf $@/contracts/Mock ; \

dist-sol-bmc: $(SOLIDITY_DIST_DIR)/bmc
cd $(SOLIDITY_DIST_DIR)/bmc ;

dist-sol-bmv: $(SOLIDITY_DIST_DIR)/bmv
cd $(SOLIDITY_DIST_DIR)/bmv ;

dist-sol-bts: $(SOLIDITY_DIST_DIR)/bts
cd $(SOLIDITY_DIST_DIR)/bts ;

# dist-sol-native_bsh: $(SOLIDITY_DIST_DIR)/bsh
# cd $(SOLIDITY_DIST_DIR)/bsh ;

dist-sol-token_bsh: $(SOLIDITY_DIST_DIR)/TokenBSH
cd $(SOLIDITY_DIST_DIR)/TokenBSH ;

clean-dist-sol:
rm -rf $(SOLIDITY_DIST_DIR)

dist-sol: dist-sol-bmc dist-sol-bts

dist-javascore:
$(BUILD_ROOT)/docker/javascore/build.sh

ICONBRIDGE_IMAGE = iconbridge:$(GL_TAG)
ICONBRIDGE_DOCKER_DIR = $(BUILD_ROOT)/build/iconbridge

iconbridge-image: iconbridge-linux
@ echo "[#] Building image $(ICONBRIDGE_IMAGE) for $(GL_VERSION)"
@ rm -rf $(ICONBRIDGE_DOCKER_DIR)
@ \
BIN_DIR=$(abspath $(LINUX_BIN_DIR)) \
BIN_VERSION=$(GL_VERSION) \
BUILD_TAGS="$(GOBUILD_TAGS)" \
DIST_DIR="$(BUILD_ROOT)/build/contracts" \
$(BUILD_ROOT)/docker/iconbridge/build.sh $(ICONBRIDGE_IMAGE) $(BUILD_ROOT) $(ICONBRIDGE_DOCKER_DIR)

.PHONY: test

test :
$(GOBUILD_ENVS) $(GOTEST) $(GOBUILD_FLAGS) ./... $(GOTEST_FLAGS)

.DEFAULT_GOAL := all
all : $(BUILD_TARGETS)
# Configuration
ROOT_DIR=${PWD}
CONTRACTS_DIR=$(ROOT_DIR)/build/contracts
JAVASCORE_DIR=$(CONTRACTS_DIR)/javascore
SOLIDITY_DIR=$(CONTRACTS_DIR)/solidity

icon-clean:
rm -rf $(ROOT_DIR)/build ; \
cd ./javascore ; \
gradle clean ; \



# TODO split ./build.sh into smaller processes and move to the make file
build-contracts:
cd ./javascore ; \
gradle clean ; \
gradle bmc:optimizedJar ; \
gradle bts:optimizedJar ; \
gradle irc2-token:optimizedJar ; \
gradle irc2Tradeable:optimizedJar ; \
cp bmc/build/libs/bmc-optimized.jar $(JAVASCORE_DIR)/bmc.jar ; \
cp bts/build/libs/bts-optimized.jar $(JAVASCORE_DIR)/bts.jar ; \
cp irc2Tradeable/build/libs/irc2Tradeable-optimized.jar $(JAVASCORE_DIR)/irc2Tradeable.jar ; \
cp irc2-token/build/libs/irc2-token-optimized.jar $(JAVASCORE_DIR)/irc2.jar ; \
46 changes: 46 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
set -e

########################################################

ROOT_DIR=${PWD}
CONTRACTS_DIR="$ROOT_DIR/build/contracts"
JAVASCORE_DIR="$CONTRACTS_DIR/javascore"
SOLIDITY_DIR="$CONTRACTS_DIR/solidity"

mkdir -p "$JAVASCORE_DIR"
mkdir -p "$SOLIDITY_DIR"
mkdir -p "$ROOT_DIR/keys/_ixh/keystore"

mkdir -p bin
cd cmd/iconvalidators
go build .
cd $ROOT_DIR

echo "Build contracts"

cd $ROOT_DIR/javascore
gradle clean
gradle bmc:optimizedJar
gradle bts:optimizedJar
gradle irc2-token:optimizedJar
gradle irc2Tradeable:optimizedJar
cp bmc/build/libs/bmc-optimized.jar $JAVASCORE_DIR/bmc.jar
cp bts/build/libs/bts-optimized.jar $JAVASCORE_DIR/bts.jar
cp irc2Tradeable/build/libs/irc2Tradeable-optimized.jar $JAVASCORE_DIR/irc2Tradeable.jar
cp irc2-token/build/libs/irc2-token-optimized.jar $JAVASCORE_DIR/irc2.jar

echo "Copy solidity"

rm -rf $ROOT_DIR/solidity/bmc/build
rm -rf $ROOT_DIR/solidity/bmc/node_modules
cp -r $ROOT_DIR/solidity/bmc $SOLIDITY_DIR/

rm -rf $ROOT_DIR/solidity/bts/build
rm -rf $ROOT_DIR/solidity/bts/node_modules
cp -r $ROOT_DIR/solidity/bts $SOLIDITY_DIR/

cd $SOLIDITY_DIR
cd bmc && yarn install
cd ..
cd bts && yarn install
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ We’ll briefly touch upon these steps so that the commands to run these process
* ### Setting up Blockchain Nodes
This requires blockchain nodes, usually available as docker images, to be run. Each node has some configuration parameters, which we require later in the process. For example, rpc endpoint, network-id and god-wallet are required to communicate and execute transactions on the network.
```sh
make cleanimglocal # Clean Previous build & deployment artifacts if present
make buildimglocal # Build BMR,BSC,ICON images
make icon-clean # Clean Previous build & deployment artifacts if present
./build.sh # Build BMR,BSC,ICON contracts
```

* ### Deploying smart contracts
Expand Down
1 change: 0 additions & 1 deletion javascore/bmc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies {

optimizedJar {
mainClassName = 'foundation.icon.btp.bmc.BTPMessageCenter'
// archivesBaseName = 'bmc'
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} { exclude "score/*" }
Expand Down
44 changes: 44 additions & 0 deletions javascore/irc2-token/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version = '0.9.1'

dependencies {
compileOnly 'foundation.icon:javaee-api:0.9.2'
implementation 'com.github.sink772:javaee-tokens:0.6.2'

testImplementation 'foundation.icon:javaee-unittest:0.9.4'
testImplementation 'org.mockito:mockito-core:4.6.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

optimizedJar {
mainClassName = 'com.iconloop.score.example.IRC2BasicToken'
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
archiveFileName = 'irc2-token.jar'
}

deployJar {
endpoints {
lisbon {
uri = 'https://lisbon.net.solidwallet.io/api/v3'
nid = 0x2
}
local {
uri = 'http://localhost:9082/api/v3'
nid = 0x3
}
}
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
parameters {
arg('_name', 'MyIRC2Token')
arg('_symbol', 'MIT')
arg('_decimals', '0x12')
arg('_initialSupply', '0x3e8')
}
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 ICONLOOP Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.iconloop.score.example;

import com.iconloop.score.token.irc2.IRC2Basic;
import score.Context;

import java.math.BigInteger;

public class IRC2BasicToken extends IRC2Basic {
public IRC2BasicToken(String _name, String _symbol, int _decimals, BigInteger _initialSupply) {
super(_name, _symbol, _decimals);

// mint the initial token supply here
Context.require(_initialSupply.compareTo(BigInteger.ZERO) >= 0);
_mint(Context.getCaller(), _initialSupply.multiply(pow10(_decimals)));
}

private static BigInteger pow10(int exponent) {
BigInteger result = BigInteger.ONE;
for (int i = 0; i < exponent; i++) {
result = result.multiply(BigInteger.TEN);
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 ICONLOOP Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.iconloop.score.example;

import com.iconloop.score.token.irc2.IRC2Burnable;
import score.Context;

import java.math.BigInteger;

public class IRC2BurnableToken extends IRC2Burnable {
public IRC2BurnableToken(String _name, String _symbol, int _decimals, BigInteger _initialSupply) {
super(_name, _symbol, _decimals);

// mint the initial token supply here
Context.require(_initialSupply.compareTo(BigInteger.ZERO) >= 0);
_mint(Context.getCaller(), _initialSupply.multiply(pow10(_decimals)));
}

private static BigInteger pow10(int exponent) {
BigInteger result = BigInteger.ONE;
for (int i = 0; i < exponent; i++) {
result = result.multiply(BigInteger.TEN);
}
return result;
}
}
Loading