Skip to content

Commit

Permalink
Merge branch 'develop' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
fijter authored Dec 10, 2021
2 parents f3de3db + 5d5e49a commit e30ba6d
Show file tree
Hide file tree
Showing 308 changed files with 15,755 additions and 10,202 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: Test
on:
pull_request:
branches: [develop]
paths-ignore:
- 'documentation/**'
- 'temupdates/**'

jobs:
build:
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ GIT_COMMIT_SHA := $(shell git rev-list -1 HEAD)
BUILD_TAGS = rocksdb,builtin_static
BUILD_LD_FLAGS = "-X github.com/iotaledger/wasp/packages/wasp.VersionHash=$(GIT_COMMIT_SHA)"

#
# You can override these e.g. as
# make test TEST_PKG=./packages/vm/core/testcore/ TEST_ARG="-v --run TestAccessNodes"
#
TEST_PKG=./...
TEST_ARG=

all: build-lint

build:
Expand All @@ -16,7 +23,7 @@ test-full: install
go test -tags $(BUILD_TAGS),runheavy ./... --timeout 60m --count 1 -failfast

test: install
go test -tags $(BUILD_TAGS) ./... --timeout 30m --count 1 -failfast
go test -tags $(BUILD_TAGS) $(TEST_PKG) --timeout 30m --count 1 -failfast $(TEST_ARG)

test-short:
go test -tags $(BUILD_TAGS) --short --count 1 -failfast ./...
Expand Down
2 changes: 1 addition & 1 deletion client/committee_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *WaspClient) GetCommitteeRecord(addr ledgerstate.Address) (*registry.Com
// GetCommitteeForChain fetches the CommitteeRecord that manages the given chain
func (c *WaspClient) GetCommitteeForChain(chainID *iscp.ChainID) (*registry.CommitteeRecord, error) {
res := &model.CommitteeRecord{}
if err := c.do(http.MethodGet, routes.GetCommitteeForChain(chainID.Base58()), nil, res); err != nil {
if err := c.do(http.MethodGet, routes.GetCommitteeForChain(chainID.Base58())+"?includeDeactivated=true", nil, res); err != nil {
return nil, err
}
return res.Record(), nil
Expand Down
27 changes: 27 additions & 0 deletions client/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package client

import (
"net/http"

"github.com/iotaledger/wasp/packages/iscp"
"github.com/iotaledger/wasp/packages/webapi/model"
"github.com/iotaledger/wasp/packages/webapi/routes"
)

// GetNodeConnectionMetrics fetches a connection to L1 metrics for all addresses
func (c *WaspClient) GetNodeConnectionMetrics() (*model.NodeConnectionMetrics, error) {
ncm := &model.NodeConnectionMetrics{}
if err := c.do(http.MethodGet, routes.GetChainsNodeConnectionMetrics(), nil, ncm); err != nil {
return nil, err
}
return ncm, nil
}

// GetNodeConnectionMetrics fetches a connection to L1 metrics by address
func (c *WaspClient) GetChainNodeConnectionMetrics(chID *iscp.ChainID) (*model.NodeConnectionMessagesMetrics, error) {
ncmm := &model.NodeConnectionMessagesMetrics{}
if err := c.do(http.MethodGet, routes.GetChainNodeConnectionMetrics(chID.Base58()), nil, ncmm); err != nil {
return nil, err
}
return ncmm, nil
}
41 changes: 21 additions & 20 deletions contracts/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"dividend",
"donatewithfeedback",
"erc20",
"erc721",
"fairauction",
"fairroulette",
"helloworld",
Expand Down
Binary file modified contracts/wasm/dividend/test/dividend_bg.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions contracts/wasm/dividend/test/dividend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func dividendDivide(ctx *wasmsolo.SoloContext, amount int64) {
divide.Func.TransferIotas(amount).Post()
}

func dividendGetFactor(ctx *wasmsolo.SoloContext, member3 *wasmsolo.SoloAgent) int64 {
func dividendGetFactor(ctx *wasmsolo.SoloContext, member *wasmsolo.SoloAgent) int64 {
getFactor := dividend.ScFuncs.GetFactor(ctx)
getFactor.Params.Address().SetValue(member3.ScAddress())
getFactor.Params.Address().SetValue(member.ScAddress())
getFactor.Func.Call()
value := getFactor.Results.Factor().Value()
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ type MutableDonation struct {
keyID wasmlib.Key32
}

func (o MutableDonation) Delete() {
wasmlib.DelKey(o.objID, o.keyID, wasmlib.TYPE_BYTES)
}

func (o MutableDonation) Exists() bool {
return wasmlib.Exists(o.objID, o.keyID, wasmlib.TYPE_BYTES)
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/wasm/donatewithfeedback/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub struct MutableDonation {
}

impl MutableDonation {
pub fn delete(&self) {
del_key(self.obj_id, self.key_id, TYPE_BYTES);
}

pub fn exists(&self) -> bool {
exists(self.obj_id, self.key_id, TYPE_BYTES)
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class MutableDonation {
this.keyID = keyID;
}

delete(): void {
wasmlib.delKey(this.objID, this.keyID, wasmlib.TYPE_BYTES);
}

exists(): boolean {
return wasmlib.exists(this.objID, this.keyID, wasmlib.TYPE_BYTES);
}
Expand Down
11 changes: 6 additions & 5 deletions contracts/wasm/erc20/go/erc20/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
func funcApprove(ctx wasmlib.ScFuncContext, f *ApproveContext) {
delegation := f.Params.Delegation().Value()
amount := f.Params.Amount().Value()
ctx.Require(amount > 0, "erc20.approve.fail: wrong 'amount' parameter")
ctx.Require(amount >= 0, "erc20.approve.fail: wrong 'amount' parameter")

// all allowances are in the map under the name of he owner
allowances := f.State.AllAllowances().GetAllowancesForAgent(ctx.Caller())
allowances.GetInt64(delegation).SetValue(amount)
f.Events.Approval(amount, ctx.Caller(), delegation)
}

// on_init is a constructor entry point. It initializes the smart contract with the
Expand Down Expand Up @@ -52,7 +53,7 @@ func funcInit(ctx wasmlib.ScFuncContext, f *InitContext) {
// - PARAM_AMOUNT: i64
func funcTransfer(ctx wasmlib.ScFuncContext, f *TransferContext) {
amount := f.Params.Amount().Value()
ctx.Require(amount > 0, "erc20.transfer.fail: wrong 'amount' parameter")
ctx.Require(amount >= 0, "erc20.transfer.fail: wrong 'amount' parameter")

balances := f.State.Balances()
sourceAgent := ctx.Caller()
Expand All @@ -62,7 +63,7 @@ func funcTransfer(ctx wasmlib.ScFuncContext, f *TransferContext) {
targetAgent := f.Params.Account().Value()
targetBalance := balances.GetInt64(targetAgent)
result := targetBalance.Value() + amount
ctx.Require(result > 0, "erc20.transfer.fail: overflow")
ctx.Require(result >= 0, "erc20.transfer.fail: overflow")

sourceBalance.SetValue(sourceBalance.Value() - amount)
targetBalance.SetValue(targetBalance.Value() + amount)
Expand All @@ -80,7 +81,7 @@ func funcTransfer(ctx wasmlib.ScFuncContext, f *TransferContext) {
func funcTransferFrom(ctx wasmlib.ScFuncContext, f *TransferFromContext) {
// validate parameters
amount := f.Params.Amount().Value()
ctx.Require(amount > 0, "erc20.transfer_from.fail: wrong 'amount' parameter")
ctx.Require(amount >= 0, "erc20.transfer_from.fail: wrong 'amount' parameter")

// allowances are in the map under the name of the account
sourceAgent := f.Params.Account().Value()
Expand All @@ -95,7 +96,7 @@ func funcTransferFrom(ctx wasmlib.ScFuncContext, f *TransferFromContext) {
targetAgent := f.Params.Recipient().Value()
targetBalance := balances.GetInt64(targetAgent)
result := targetBalance.Value() + amount
ctx.Require(result > 0, "erc20.transfer_from.fail: overflow")
ctx.Require(result >= 0, "erc20.transfer_from.fail: overflow")

sourceBalance.SetValue(sourceBalance.Value() - amount)
targetBalance.SetValue(targetBalance.Value() + amount)
Expand Down
8 changes: 8 additions & 0 deletions contracts/wasm/erc20/go/erc20/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import "github.com/iotaledger/wasp/packages/vm/wasmlib/go/wasmlib"

type Erc20Events struct{}

func (e Erc20Events) Approval(amount int64, owner wasmlib.ScAgentID, spender wasmlib.ScAgentID) {
wasmlib.NewEventEncoder("erc20.approval").
Int64(amount).
AgentID(owner).
AgentID(spender).
Emit()
}

func (e Erc20Events) Transfer(amount int64, from wasmlib.ScAgentID, to wasmlib.ScAgentID) {
wasmlib.NewEventEncoder("erc20.transfer").
Int64(amount).
Expand Down
4 changes: 4 additions & 0 deletions contracts/wasm/erc20/schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Erc20
description: ERC-20 PoC for IOTA Smart Contracts
events:
approval:
amount: Int64
owner: AgentID
spender: AgentID
transfer:
amount: Int64
from: AgentID
Expand Down
11 changes: 6 additions & 5 deletions contracts/wasm/erc20/src/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ use crate::*;
pub fn func_approve(ctx: &ScFuncContext, f: &ApproveContext) {
let delegation = f.params.delegation().value();
let amount = f.params.amount().value();
ctx.require(amount > 0, "erc20.approve.fail: wrong 'amount' parameter");
ctx.require(amount >= 0, "erc20.approve.fail: wrong 'amount' parameter");

// all allowances are in the map under the name of he owner
let allowances = f.state.all_allowances().get_allowances_for_agent(&ctx.caller());
allowances.get_int64(&delegation).set_value(amount);
f.events.approval(amount, &ctx.caller(), &delegation);
}

// on_init is a constructor entry point. It initializes the smart contract with the
Expand Down Expand Up @@ -50,7 +51,7 @@ pub fn func_init(ctx: &ScFuncContext, f: &InitContext) {
// - PARAM_AMOUNT: i64
pub fn func_transfer(ctx: &ScFuncContext, f: &TransferContext) {
let amount = f.params.amount().value();
ctx.require(amount > 0, "erc20.transfer.fail: wrong 'amount' parameter");
ctx.require(amount >= 0, "erc20.transfer.fail: wrong 'amount' parameter");

let balances = f.state.balances();
let source_agent = ctx.caller();
Expand All @@ -60,7 +61,7 @@ pub fn func_transfer(ctx: &ScFuncContext, f: &TransferContext) {
let target_agent = f.params.account().value();
let target_balance = balances.get_int64(&target_agent);
let result = target_balance.value() + amount;
ctx.require(result > 0, "erc20.transfer.fail: overflow");
ctx.require(result >= 0, "erc20.transfer.fail: overflow");

source_balance.set_value(source_balance.value() - amount);
target_balance.set_value(target_balance.value() + amount);
Expand All @@ -78,7 +79,7 @@ pub fn func_transfer(ctx: &ScFuncContext, f: &TransferContext) {
pub fn func_transfer_from(ctx: &ScFuncContext, f: &TransferFromContext) {
// validate parameters
let amount = f.params.amount().value();
ctx.require(amount > 0, "erc20.transfer_from.fail: wrong 'amount' parameter");
ctx.require(amount >= 0, "erc20.transfer_from.fail: wrong 'amount' parameter");

// allowances are in the map under the name of the account
let source_agent = f.params.account().value();
Expand All @@ -93,7 +94,7 @@ pub fn func_transfer_from(ctx: &ScFuncContext, f: &TransferFromContext) {
let target_agent = f.params.recipient().value();
let target_balance = balances.get_int64(&target_agent);
let result = target_balance.value() + amount;
ctx.require(result > 0, "erc20.transfer_from.fail: overflow");
ctx.require(result >= 0, "erc20.transfer_from.fail: overflow");

source_balance.set_value(source_balance.value() - amount);
target_balance.set_value(target_balance.value() + amount);
Expand Down
8 changes: 8 additions & 0 deletions contracts/wasm/erc20/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ pub struct Erc20Events {

impl Erc20Events {

pub fn approval(&self, amount: i64, owner: &ScAgentID, spender: &ScAgentID) {
let mut encoder = EventEncoder::new("erc20.approval");
encoder.int64(amount);
encoder.agent_id(&owner);
encoder.agent_id(&spender);
encoder.emit();
}

pub fn transfer(&self, amount: i64, from: &ScAgentID, to: &ScAgentID) {
let mut encoder = EventEncoder::new("erc20.transfer");
encoder.int64(amount);
Expand Down
Binary file modified contracts/wasm/erc20/test/erc20_bg.wasm
Binary file not shown.
Loading

0 comments on commit e30ba6d

Please sign in to comment.