diff --git a/Dockerfile.armhf b/Dockerfile.armhf index 1663f53ac126503e3b68aaad7f611f69e85f1ef1..9f8249d9f14c6386647a55eb62980863fd538e6f 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -1,6 +1,6 @@ # Pull base image. FROM quay.io/eris/build:arm -MAINTAINER Eris Industries <support@erisindustries.com> +MAINTAINER Monax Industries <support@monax.io> # Expose ports for 1337:eris-db API; 46656:tendermint-peer; 46657:tendermint-rpc EXPOSE 1337 diff --git a/Makefile b/Makefile index 29bbd1a874f96fb7813e15138112d522399992d6..a05fe57e210c74affc132397a405f4cee63813fb 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,11 @@ hell: go build -o ${REPO}/target/hell ./util/hell/cmd/hell/main.go ./target/hell $(filter-out $@,$(MAKECMDGOALS)) +# Dumps Solidity interface contracts for SNatives +.PHONY: snatives +snatives: + @go run ./util/snatives/cmd/main.go + ### Building github.com/eris-ltd/eris-db # build all targets in github.com/eris-ltd/eris-db diff --git a/README.md b/README.md index fd30fd6b44f82d2ba9d5e9d88715a76b4247871e..bd74638527dcdb4fccf3f58113f77f295b3660df 100644 --- a/README.md +++ b/README.md @@ -58,4 +58,4 @@ See the [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more details. ## License -[GPL-3](license.md) +[Apache 2.0](license.md) diff --git a/account/account.go b/account/account.go index 99b545f212a8c3be9322eecdf74fe6d8ad3b4f10..d2f80c97cea0f46799374491247d3fc39524fe42 100644 --- a/account/account.go +++ b/account/account.go @@ -1,32 +1,31 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package account // TODO: [ben] Account and PrivateAccount need to become a pure interface // and then move the implementation to the manager types. // Eg, Geth has its accounts, different from ErisMint -package account - import ( "bytes" "fmt" "io" + "github.com/eris-ltd/eris-db/common/sanity" ptypes "github.com/eris-ltd/eris-db/permission/types" - . "github.com/tendermint/go-common" + "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" ) @@ -42,7 +41,7 @@ func SignBytes(chainID string, o Signable) []byte { buf, n, err := new(bytes.Buffer), new(int), new(error) o.WriteSignBytes(chainID, buf, n, err) if *err != nil { - PanicCrisis(err) + sanity.PanicCrisis(err) } return buf.Bytes() diff --git a/account/priv_account.go b/account/priv_account.go index 52c0ab7710f40bb5708bb5b1cd4a44f413d76d58..6a738445b269ae6f1b511ce7c340ecae0ddb259c 100644 --- a/account/priv_account.go +++ b/account/priv_account.go @@ -1,28 +1,29 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package account // TODO: [ben] Account and PrivateAccount need to become a pure interface // and then move the implementation to the manager types. // Eg, Geth has its accounts, different from ErisMint -package account - import ( + "fmt" + + "github.com/eris-ltd/eris-db/common/sanity" + "github.com/tendermint/ed25519" - . "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" ) @@ -49,7 +50,7 @@ func (pA *PrivAccount) Sign(chainID string, o Signable) crypto.Signature { } func (pA *PrivAccount) String() string { - return Fmt("PrivAccount{%X}", pA.Address) + return fmt.Sprintf("PrivAccount{%X}", pA.Address) } //---------------------------------------- @@ -90,7 +91,7 @@ func GenPrivAccountFromSecret(secret string) *PrivAccount { func GenPrivAccountFromPrivKeyBytes(privKeyBytes []byte) *PrivAccount { if len(privKeyBytes) != 64 { - PanicSanity(Fmt("Expected 64 bytes but got %v", len(privKeyBytes))) + sanity.PanicSanity(fmt.Sprintf("Expected 64 bytes but got %v", len(privKeyBytes))) } var privKeyArray [64]byte copy(privKeyArray[:], privKeyBytes) diff --git a/blockchain/filter.go b/blockchain/filter.go index 06743a64a9842c9f5eeae20780479016dc128ff9..26ff58d107ce903a02709820f41e795c2363f0e3 100644 --- a/blockchain/filter.go +++ b/blockchain/filter.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 blockchain import ( diff --git a/blockchain/types/blockchain.go b/blockchain/types/blockchain.go index 80ef14dbcdba92607fa21faa159420ce3cd6d1e5..317e2a9f8680a4e4b4cff10420f098beb7d3c3bd 100644 --- a/blockchain/types/blockchain.go +++ b/blockchain/types/blockchain.go @@ -1,25 +1,23 @@ // +build !arm -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package types // Blockchain is part of the pipe for ErisMint and provides the implementation // for the pipe to call into the ErisMint application -package types - type Blockchain interface { BlockStore ChainId() string diff --git a/blockchain/types/blockstore.go b/blockchain/types/blockstore.go index 41b426a4816978b8929edeb9ce7d60f018071b08..6c992e258a232e9dc52d88d9b970f65d6787596e 100644 --- a/blockchain/types/blockstore.go +++ b/blockchain/types/blockstore.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import tendermint_types "github.com/tendermint/tendermint/types" diff --git a/client/cmd/eris-client.go b/client/cmd/eris-client.go index f073141998de883a7134df05199485f30b5e53e0..681dc525b3dccfc7806f38e6de9bb256524934d7 100644 --- a/client/cmd/eris-client.go +++ b/client/cmd/eris-client.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 commands @@ -35,7 +33,7 @@ var ErisClientCmd = &cobra.Command{ Short: "Eris-client interacts with a running Eris chain.", Long: `Eris-client interacts with a running Eris chain. -Made with <3 by Eris Industries. +Made with <3 by Monax Industries. Complete documentation is available at https://monax.io/docs/documentation ` + "\nVERSION:\n " + version.VERSION, diff --git a/client/cmd/eris-client/main.go b/client/cmd/eris-client/main.go index 8219af99a32a54afdbeff73b10d13f88cf38f3a3..7dd05955cc42c71affe202f9ba9ece27d10919ac 100644 --- a/client/cmd/eris-client/main.go +++ b/client/cmd/eris-client/main.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 main diff --git a/client/cmd/genesis.go b/client/cmd/genesis.go index ad8d01216b3fdcbc1304c7e8787581e533a49403..5b480e0818935ecf00d7991759fbbaabf3295a5b 100644 --- a/client/cmd/genesis.go +++ b/client/cmd/genesis.go @@ -1,8 +1,23 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 commands import ( "fmt" + "github.com/eris-ltd/eris-db/common/sanity" "github.com/eris-ltd/eris-db/genesis" "github.com/spf13/cobra" @@ -23,7 +38,7 @@ var GenesisGenCmd = &cobra.Command{ // TODO refactor to not panic genesisFile, err := genesis.GenerateKnown(args[0], AccountsPathFlag, ValidatorsPathFlag) if err != nil { - panic(err) + sanity.PanicSanity(err) } fmt.Println(genesisFile) // may want to save somewhere instead }, diff --git a/client/cmd/status.go b/client/cmd/status.go index 08807956dc1012a49aea2b49e1a50c8ac975e974..4b5b11afb47105ca3aa506c5e4910ba2f4bacd29 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 commands diff --git a/client/cmd/transaction.go b/client/cmd/transaction.go index a527577481c7fec56dc87ac25383cbfef6b7f3f7..28af969f90cde0adff6f2a73abfd3aed4bb62294 100644 --- a/client/cmd/transaction.go +++ b/client/cmd/transaction.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 commands diff --git a/client/methods/call.go b/client/methods/call.go index 1bdcbdfeceea4f9c41663c244d76cddf392a6591..86c793983fdde5b09b685fd3b939c71d7ad59932 100644 --- a/client/methods/call.go +++ b/client/methods/call.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 methods diff --git a/client/methods/helpers.go b/client/methods/helpers.go index 13c7138d26f1a9ddcc15a7e38fe505b6df43acef..a97c92c104bdf3ee08f1d3d99c9d7c281eb21b36 100644 --- a/client/methods/helpers.go +++ b/client/methods/helpers.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 methods diff --git a/client/methods/send.go b/client/methods/send.go index 65c2db37e5584c6e11205097aa0d3c01c45343bb..8fa10230200098111a282e43696c591118c93e8b 100644 --- a/client/methods/send.go +++ b/client/methods/send.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 methods diff --git a/client/methods/status.go b/client/methods/status.go index dd5bf72523bc9ba5277fadf10fb6e9bf2c1d7209..f1fb6348495fa962818d8d4dd27e1dab20fe0167 100644 --- a/client/methods/status.go +++ b/client/methods/status.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 methods diff --git a/client/mock/client_mock.go b/client/mock/client_mock.go index adcde24bd7ba41b53b2f21feedb62189da477a92..f1e80895ff184f0f39ffd9dec3d5004d83afc852 100644 --- a/client/mock/client_mock.go +++ b/client/mock/client_mock.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 mock diff --git a/client/node_client.go b/client/node_client.go index 4502d77cca860fc0708f8ec14248502a515843ac..56dd425e22498741cb6efae6c6e381111a20e24d 100644 --- a/client/node_client.go +++ b/client/node_client.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 client diff --git a/client/rpc/client.go b/client/rpc/client.go index 77ed13b528cf10853ab790088a456e777ecf910c..d82a5f9448065f970525b5624ac969b1da8bd4ad 100644 --- a/client/rpc/client.go +++ b/client/rpc/client.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc @@ -99,19 +97,6 @@ func Name(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr, return tx, nil } -type PermFunc struct { - Name string - Args string -} - -var PermsFuncs = []PermFunc{ - {"set_base", "address, permission flag, value"}, - {"unset_base", "address, permission flag"}, - {"set_global", "permission flag, value"}, - {"add_role", "address, role"}, - {"rm_role", "address, role"}, -} - func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addrS, nonceS, permFunc string, argsS []string) (*txs.PermissionsTx, error) { pub, _, nonce, err := checkCommon(nodeClient, keyClient, pubkey, addrS, "0", nonceS) if err != nil { @@ -119,13 +104,13 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, } var args ptypes.PermArgs switch permFunc { - case "set_base": + case "setBase": addr, pF, err := decodeAddressPermFlag(argsS[0], argsS[1]) if err != nil { return nil, err } if len(argsS) != 3 { - return nil, fmt.Errorf("set_base also takes a value (true or false)") + return nil, fmt.Errorf("setBase also takes a value (true or false)") } var value bool if argsS[2] == "true" { @@ -136,13 +121,13 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, return nil, fmt.Errorf("Unknown value %s", argsS[2]) } args = &ptypes.SetBaseArgs{addr, pF, value} - case "unset_base": + case "unsetBase": addr, pF, err := decodeAddressPermFlag(argsS[0], argsS[1]) if err != nil { return nil, err } args = &ptypes.UnsetBaseArgs{addr, pF} - case "set_global": + case "setGlobal": pF, err := ptypes.PermStringToFlag(argsS[0]) if err != nil { return nil, err @@ -156,13 +141,13 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, return nil, fmt.Errorf("Unknown value %s", argsS[1]) } args = &ptypes.SetGlobalArgs{pF, value} - case "add_role": + case "addRole": addr, err := hex.DecodeString(argsS[0]) if err != nil { return nil, err } args = &ptypes.AddRoleArgs{addr, argsS[1]} - case "rm_role": + case "removeRole": addr, err := hex.DecodeString(argsS[0]) if err != nil { return nil, err diff --git a/client/rpc/client_test.go b/client/rpc/client_test.go index 6541bd3f9f3b92b29a3c1c231669afde4350a0a2..b0806910fe73f91547a3b15b7d5c1f1163974567 100644 --- a/client/rpc/client_test.go +++ b/client/rpc/client_test.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc @@ -147,7 +145,7 @@ func testPermissions(t *testing.T, nonceString := "" _, err := Permissions(nodeClient, keyClient, publicKeyString, addressString, - nonceString, "set_base", []string{permAddressString, "root", "true"}) + nonceString, "setBase", []string{permAddressString, "root", "true"}) if err != nil { t.Logf("Error in PermissionsTx: %s", err) t.Fail() diff --git a/client/rpc/client_util.go b/client/rpc/client_util.go index df8ffe3f0fe77cd927014794878b6ada6806f421..f086c68b2329866c17f6c5c92a128e5e255cc974 100644 --- a/client/rpc/client_util.go +++ b/client/rpc/client_util.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc diff --git a/client/websocket_client.go b/client/websocket_client.go index 429958aad169eab380d832f83a7b70e868ebde08..d3949e652f2ab40ee357bdb95910f9032626e938 100644 --- a/client/websocket_client.go +++ b/client/websocket_client.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 client diff --git a/client/ws_client.go b/client/ws_client.go index d60986b6f9a41575642dbf963aaceb281d52dfe5..cdcb0b570af2b87926e888d0ef009b125d89e8f5 100644 --- a/client/ws_client.go +++ b/client/ws_client.go @@ -1,4 +1,17 @@ -// Websocket client implementation. This will be used in tests. +// Copyright 2017 Monax Industries Limited +// +// 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 client // NOTE: this websocket client acts on rpc/v0, @@ -6,6 +19,7 @@ package client // and will be deprecated after 0.12 // It is recommended to use the interfaces NodeClient // and NodeWebsocketClient. +// Websocket client implementation. This will be used in tests. import ( "fmt" diff --git a/cmd/eris-db.go b/cmd/eris-db.go index 5f66acdca4d5d50304bb864ddedd2e054a1a30fe..c0f6e582441b707f9655a4809cca054e4f66c136 100644 --- a/cmd/eris-db.go +++ b/cmd/eris-db.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 commands diff --git a/cmd/eris-db/main.go b/cmd/eris-db/main.go index 47870377f4123834fe8b1c99474c08819da54c12..d293b374f4e5c8919860293a9534e63b576f9bf6 100644 --- a/cmd/eris-db/main.go +++ b/cmd/eris-db/main.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 main diff --git a/cmd/serve.go b/cmd/serve.go index 29319b1fd815498dae5ac82659211afacc8280c8..4eceefc3810603f8fb3e091ce09317a1606b2c1b 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 commands @@ -23,13 +21,13 @@ import ( "path" "syscall" - "github.com/spf13/cobra" - "github.com/eris-ltd/eris-db/core" "github.com/eris-ltd/eris-db/definitions" "github.com/eris-ltd/eris-db/logging" "github.com/eris-ltd/eris-db/logging/lifecycle" "github.com/eris-ltd/eris-db/util" + + "github.com/spf13/cobra" ) const ( diff --git a/common/math/integral/integral_math.go b/common/math/integral/integral_math.go index 8cdc6ee18d3a4a1e8ed777527d9605d325a4a61c..863b92114352b6a12568f8dcc778708adbfd5283 100644 --- a/common/math/integral/integral_math.go +++ b/common/math/integral/integral_math.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 integral func MaxInt8(a, b int8) int8 { diff --git a/common/random/random.go b/common/random/random.go new file mode 100644 index 0000000000000000000000000000000000000000..e2a095e2a559980abf7ba3a5ea105c491baaeec8 --- /dev/null +++ b/common/random/random.go @@ -0,0 +1,154 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 random + +import ( + crand "crypto/rand" + "math/rand" + "time" + + "github.com/eris-ltd/eris-db/common/sanity" +) + +const ( + strChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" // 62 characters +) + +func init() { + b := cRandBytes(8) + var seed uint64 + for i := 0; i < 8; i++ { + seed |= uint64(b[i]) + seed <<= 8 + } + rand.Seed(int64(seed)) +} + +// Constructs an alphanumeric string of given length. +func RandStr(length int) string { + chars := []byte{} +MAIN_LOOP: + for { + val := rand.Int63() + for i := 0; i < 10; i++ { + v := int(val & 0x3f) // rightmost 6 bits + if v >= 62 { // only 62 characters in strChars + val >>= 6 + continue + } else { + chars = append(chars, strChars[v]) + if len(chars) == length { + break MAIN_LOOP + } + val >>= 6 + } + } + } + + return string(chars) +} + +func RandUint16() uint16 { + return uint16(rand.Uint32() & (1<<16 - 1)) +} + +func RandUint32() uint32 { + return rand.Uint32() +} + +func RandUint64() uint64 { + return uint64(rand.Uint32())<<32 + uint64(rand.Uint32()) +} + +func RandUint() uint { + return uint(rand.Int()) +} + +func RandInt16() int16 { + return int16(rand.Uint32() & (1<<16 - 1)) +} + +func RandInt32() int32 { + return int32(rand.Uint32()) +} + +func RandInt64() int64 { + return int64(rand.Uint32())<<32 + int64(rand.Uint32()) +} + +func RandInt() int { + return rand.Int() +} + +// Distributed pseudo-exponentially to test for various cases +func RandUint16Exp() uint16 { + bits := rand.Uint32() % 16 + if bits == 0 { + return 0 + } + n := uint16(1 << (bits - 1)) + n += uint16(rand.Int31()) & ((1 << (bits - 1)) - 1) + return n +} + +// Distributed pseudo-exponentially to test for various cases +func RandUint32Exp() uint32 { + bits := rand.Uint32() % 32 + if bits == 0 { + return 0 + } + n := uint32(1 << (bits - 1)) + n += uint32(rand.Int31()) & ((1 << (bits - 1)) - 1) + return n +} + +// Distributed pseudo-exponentially to test for various cases +func RandUint64Exp() uint64 { + bits := rand.Uint32() % 64 + if bits == 0 { + return 0 + } + n := uint64(1 << (bits - 1)) + n += uint64(rand.Int63()) & ((1 << (bits - 1)) - 1) + return n +} + +func RandFloat32() float32 { + return rand.Float32() +} + +func RandTime() time.Time { + return time.Unix(int64(RandUint64Exp()), 0) +} + +func RandBytes(n int) []byte { + bs := make([]byte, n) + for i := 0; i < n; i++ { + bs[i] = byte(rand.Intn(256)) + } + return bs +} + +// NOTE: This relies on the os's random number generator. +// For real security, we should salt that with some seed. +// See github.com/tendermint/go-crypto for a more secure reader. +func cRandBytes(numBytes int) []byte { + b := make([]byte, numBytes) + _, err := crand.Read(b) + if err != nil { + sanity.PanicCrisis(err) + } + return b +} diff --git a/common/sanity/sanity.go b/common/sanity/sanity.go new file mode 100644 index 0000000000000000000000000000000000000000..63fe7fd9e2f1a53ec7c379b7b199d082044f5b1b --- /dev/null +++ b/common/sanity/sanity.go @@ -0,0 +1,48 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 sanity + +import ( + "fmt" +) + +//-------------------------------------------------------------------------------------------------- +// panic wrappers +// NOTE: [ben] Fail fast and fail hard, these are wrappers that point to code that needs +// to be addressed, but simplify finding them in the code; + +// A panic resulting from a sanity check means there is a programmer error +// and some gaurantee is not satisfied. +func PanicSanity(v interface{}) { + panic(fmt.Sprintf("Paniced on a Sanity Check: %v", v)) +} + +// A panic here means something has gone horribly wrong, in the form of data corruption or +// failure of the operating system. In a correct/healthy system, these should never fire. +// If they do, it's indicative of a much more serious problem. +func PanicCrisis(v interface{}) { + panic(fmt.Sprintf("Paniced on a Crisis: %v", v)) +} + +// Indicates a failure of consensus. Someone was malicious or something has +// gone horribly wrong. These should really boot us into an "emergency-recover" mode +func PanicConsensus(v interface{}) { + panic(fmt.Sprintf("Paniced on a Consensus Failure: %v", v)) +} + +// For those times when we're not sure if we should panic +func PanicQ(v interface{}) { + panic(fmt.Sprintf("Paniced questionably: %v", v)) +} diff --git a/config/config.go b/config/config.go index 3dc213f4eef06f0c1ac93779393a15e6ea3037cd..243a67ed835b54b133211e431433ce868e0ba3b5 100644 --- a/config/config.go +++ b/config/config.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Monax Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 config diff --git a/config/config_test.go b/config/config_test.go index e01346e846133f931b825009eb627aa6616f4b3b..1f5a95c1963a726173813cb84a0f1f920b84accd 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Monax Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 config diff --git a/config/dump_config_test.go b/config/dump_config_test.go index 4ea3dd0598fa3b78cdffeae44e95c4d8d35212a5..5d238c9e84afd53ab19da4a70bcb88d3fe77d525 100644 --- a/config/dump_config_test.go +++ b/config/dump_config_test.go @@ -1,6 +1,20 @@ // +build dumpconfig // Space above matters +// Copyright 2017 Monax Industries Limited +// +// 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 config import ( diff --git a/config/module.go b/config/module.go index 39c131d269ae7861b69fdc80b039065a6c909b7e..da0218c5ce47ea9b71f2b9d2b6a52883cb711a5d 100644 --- a/config/module.go +++ b/config/module.go @@ -1,21 +1,20 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package config // config defines simple types in a separate package to avoid cyclical imports -package config import ( viper "github.com/spf13/viper" diff --git a/config/templates.go b/config/templates.go index f38cbecabc027839baabe26406108e0744741f12..c292eb1feb7533715fd7a6a96d9e8812a07716cb 100644 --- a/config/templates.go +++ b/config/templates.go @@ -1,35 +1,32 @@ -// Copyright 2015, 2016 Monax Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 config -const headerCopyright = `# Copyright 2015-2017 Monax Industries Limited. -# This file is part of the Monax platform (Monax) - -# Monax is free software: you can use, redistribute it and/or modify -# it only under the terms of the GNU General Public License, version -# 3, as published by the Free Software Foundation. - -# Monax is distributed WITHOUT ANY WARRANTY pursuant to -# the terms of the Gnu General Public Licence, version 3, including -# (but not limited to) Clause 15 thereof. See the text of the -# GNU General Public License, version 3 for full terms. - -# You should have received a copy of the GNU General Public License, -# version 3, with Monax. If not, see <http://www.gnu.org/licenses/>. +const headerCopyright = `# Copyright 2017 Monax Industries Limited +# +# 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. # This is a TOML configuration for Eris-DB chains generated by Eris. diff --git a/config/viper.go b/config/viper.go index cb59f540c3548177a1bbb23a356ed28c61583aff..cefd2f2a8f5ec3b0abc89dd83f0dafa0f6b60951 100644 --- a/config/viper.go +++ b/config/viper.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 config import ( diff --git a/consensus/config.go b/consensus/config.go index d676d8c214f8c794aaea43a845260f9407d2d311..c2a7cdf4977e27fa38fed5ca92e310048c19842c 100644 --- a/consensus/config.go +++ b/consensus/config.go @@ -1,21 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// version provides the current Eris-DB version and a VersionIdentifier -// for the modules to identify their version with. +// Copyright 2017 Monax Industries Limited +// +// 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 consensus diff --git a/consensus/consensus.go b/consensus/consensus.go index 2f4132d6e4e5aa89975b3100d913f86d4af72e7b..77b7ffff3e0b6a9be768bca2f7de5450e7c6bc2b 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 consensus diff --git a/consensus/tendermint/config.go b/consensus/tendermint/config.go index 094d7979e429ae16ec2bd3ff39e59e926895a77d..c55115f7254527da1dce0549f07224ce72e6473a 100644 --- a/consensus/tendermint/config.go +++ b/consensus/tendermint/config.go @@ -1,21 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// version provides the current Eris-DB version and a VersionIdentifier -// for the modules to identify their version with. +// Copyright 2017 Monax Industries Limited +// +// 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 tendermint diff --git a/consensus/tendermint/local_client.go b/consensus/tendermint/local_client.go index 97b732cac6ab66237ce6250478a6a886855a3b6f..2a2cd873018966cfb318a4d7fe080f06bb8b30d1 100644 --- a/consensus/tendermint/local_client.go +++ b/consensus/tendermint/local_client.go @@ -1,27 +1,22 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// version provides the current Eris-DB version and a VersionIdentifier -// for the modules to identify their version with. +package tendermint // This file is originally based on github.com/tendermint/tmsp/client/... // .../local_client.go -package tendermint - import ( "sync" diff --git a/consensus/tendermint/tendermint.go b/consensus/tendermint/tendermint.go index 5adc08e1a2619723123088901bea595f75a300eb..b4d9046b7b9fd37418babecbab1904d80dd14774 100644 --- a/consensus/tendermint/tendermint.go +++ b/consensus/tendermint/tendermint.go @@ -1,21 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// version provides the current Eris-DB version and a VersionIdentifier -// for the modules to identify their version with. +// Copyright 2017 Monax Industries Limited +// +// 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 tendermint diff --git a/consensus/tendermint/version.go b/consensus/tendermint/version.go index 870d1313bf43977a8976f0415d07f1aa5d1f2b2d..a759e54411942593e4e2f7ba41661190a3b20d7f 100644 --- a/consensus/tendermint/version.go +++ b/consensus/tendermint/version.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 tendermint diff --git a/consensus/tendermint/version_test.go b/consensus/tendermint/version_test.go index 25985ec115142e63d0956c8ea9bf311b8ce2e08c..bfbbe3e762bde36304cf59379b04c94d13cff4ae 100644 --- a/consensus/tendermint/version_test.go +++ b/consensus/tendermint/version_test.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 tendermint diff --git a/consensus/tmsp/server.go b/consensus/tmsp/server.go index 62abb9d641d747b748972e02e1b1d9b77ebacf47..e961bc50c6d50bb01e12a1eb7a62d95e05cdad40 100644 --- a/consensus/tmsp/server.go +++ b/consensus/tmsp/server.go @@ -1,23 +1,21 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package tmsp // Taken originally from github.com/tendermint/tmsp/server.go -package tmsp - import ( "bufio" "fmt" diff --git a/consensus/tmsp/version.go b/consensus/tmsp/version.go index 266b37d792c4b606cdd547469f05d050edcc0b3b..a5422c211433acb164359eb4cb8a426e748a4bc1 100644 --- a/consensus/tmsp/version.go +++ b/consensus/tmsp/version.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 tmsp diff --git a/consensus/types/consensus_engine.go b/consensus/types/consensus_engine.go index ea02d3b2ec36459765f755cfd2f11930a622b38c..0ca7bd481b905c2e074341a3b244fcd285ce7461 100644 --- a/consensus/types/consensus_engine.go +++ b/consensus/types/consensus_engine.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( diff --git a/consensus/types/consensus_state.go b/consensus/types/consensus_state.go index a22febd4fcd8ea4d37023b3a4ac00e84583ae7e5..74d8b4b4a2167d5061bc120ac930409ace542570 100644 --- a/consensus/types/consensus_state.go +++ b/consensus/types/consensus_state.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( diff --git a/consensus/types/peer.go b/consensus/types/peer.go index 78ddc885c220dc02e859d177a5bd0bedd35440b2..c123cf5c022e43d7a0224c55c14623913a4f12c4 100644 --- a/consensus/types/peer.go +++ b/consensus/types/peer.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import "github.com/tendermint/go-p2p" diff --git a/consensus/types/validator.go b/consensus/types/validator.go index 8feefb1f3563c5f690f20448c1056dc1c249c0c1..86fcfac1a6d7badbd2792eb5cae07f7156b32038 100644 --- a/consensus/types/validator.go +++ b/consensus/types/validator.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( diff --git a/core/config.go b/core/config.go index 5a10047e276bd1db6a06d717e6f141242e340026..9090c28ae91fa7fa79ffaaa997b71afec47672b3 100644 --- a/core/config.go +++ b/core/config.go @@ -1,22 +1,21 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited // -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. +// 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 // -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// http://www.apache.org/licenses/LICENSE-2.0 // -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// 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. // config.go keeps explicit structures on the runtime configuration of // Eris-DB and all modules. It loads these from the Viper configuration // loaded in `definitions.Do` + package core import ( diff --git a/core/core.go b/core/core.go index 6c58d1a3312eba6c17cf06c121be1bbb201d48eb..decb567c78eeffce45b95d4d2361fc59697db0f6 100644 --- a/core/core.go +++ b/core/core.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 core diff --git a/core/types/types.go b/core/types/types.go index ecb6fc95293cf98d6125ccf0f4450a33fdc0b0e3..abe9fd0c924b8ca2560da4a9365f8de0e5418002 100644 --- a/core/types/types.go +++ b/core/types/types.go @@ -1,23 +1,22 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package types // TODO: [ben] this is poorly constructed but copied over // from eris-db/erisdb/pipe/types to make incremental changes and allow // for a discussion around the proper defintion of the needed types. -package types import ( // NodeInfo (drop this!) diff --git a/definitions/client_do.go b/definitions/client_do.go index 849977fa3312c0dd6cc90b650592c2a9caa0b172..dc7c9c7e2f534a7eae150aac095bf40ba249012c 100644 --- a/definitions/client_do.go +++ b/definitions/client_do.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 definitions diff --git a/definitions/do.go b/definitions/do.go index f022aabbc2495d91933b0da38cbd39c4f0be4399..e89b69ffb375bd3a255dec6097c60a69591485f7 100644 --- a/definitions/do.go +++ b/definitions/do.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 definitions diff --git a/definitions/pipe.go b/definitions/pipe.go index a32a4cdf24cd43e63b95f0defcfb95ecbc311057..e00e46ed80fb10674222a55c29c92f276e814632 100644 --- a/definitions/pipe.go +++ b/definitions/pipe.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 definitions diff --git a/definitions/tendermint_pipe.go b/definitions/tendermint_pipe.go index e933194d7cb28c1f2bbb163f0ef9b0009d4509f6..8fd5a9bb5e3dd75f59336b63825788e10cbe07ba 100644 --- a/definitions/tendermint_pipe.go +++ b/definitions/tendermint_pipe.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 definitions diff --git a/docs/generator.go b/docs/generator.go index c3aa23876050cdac4db9d63feb5fa8b82e0655e8..404b1593fcec1b9bc8cd2c0ba6c679c60854bb71 100644 --- a/docs/generator.go +++ b/docs/generator.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 main import ( diff --git a/docs/generator/generator.go b/docs/generator/generator.go index fee2e3d5cfbb524b89b2b61b95fba9b6cd813d43..296704a4841d3a652fc0eb2090088f2c15863a2b 100644 --- a/docs/generator/generator.go +++ b/docs/generator/generator.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 generator import ( diff --git a/event/event_cache.go b/event/event_cache.go index 7b6bc356cdf528a390730daa1ac0cabcb2d5749e..474c892d08161476d5c177ec032226c2bc01ab31 100644 --- a/event/event_cache.go +++ b/event/event_cache.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 event import ( diff --git a/event/event_cache_test.go b/event/event_cache_test.go index 35ce6d7ed0cbdc45c3b838d831b993fddfbbb42b..573eed113af6fb60306597530a647c437eaef102 100644 --- a/event/event_cache_test.go +++ b/event/event_cache_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 event import ( @@ -13,7 +27,7 @@ import ( "github.com/stretchr/testify/assert" ) -var mockInterval = 10 * time.Millisecond +var mockInterval = 40 * time.Millisecond type mockSub struct { subId string diff --git a/event/events.go b/event/events.go index ec790a9ed8b1d120a46ecf1642bec840756fcbdd..4ef6ddac0e0db621043a08155bf3728afc51da04 100644 --- a/event/events.go +++ b/event/events.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 event diff --git a/event/events_test.go b/event/events_test.go index 51d185ecb0ad5c012c528c2cf1eeb7e3165ab182..af6d9530377eceb4a184ded8e4b6b030458df35e 100644 --- a/event/events_test.go +++ b/event/events_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 event import ( diff --git a/event/filters.go b/event/filters.go index 948a2f012af4275782adcd480248cc424b459ca6..ea04e989f45a8c61dd46370bebcaac02a86fc727 100644 --- a/event/filters.go +++ b/event/filters.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 event import ( diff --git a/event_new/event.go b/event_new/event.go deleted file mode 100644 index 9553b3921991404a0298819c7b930e829fa67087..0000000000000000000000000000000000000000 --- a/event_new/event.go +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// This code is ported over into Eris-RT from Go-Ethereum and further adapted, -// with many thanks to the Ethereum foundation and the Go-Ethereum team. - -// Package event implements an event multiplexer. -package event - -import ( - "errors" - "fmt" - "reflect" - "sync" - "time" -) - -// Event is a time-tagged notification pushed to subscribers. -type Event struct { - Time time.Time - Data interface{} -} - -// Subscription is implemented by event subscriptions. -type Subscription interface { - // Chan returns a channel that carries events. - // Implementations should return the same channel - // for any subsequent calls to Chan. - Chan() <-chan *Event - - // Unsubscribe stops delivery of events to a subscription. - // The event channel is closed. - // Unsubscribe can be called more than once. - Unsubscribe() -} - -// A TypeMux dispatches events to registered receivers. Receivers can be -// registered to handle events of certain type. Any operation -// called after mux is stopped will return ErrMuxClosed. -// -// The zero value is ready to use. -type TypeMux struct { - mutex sync.RWMutex - subm map[reflect.Type][]*muxsub - stopped bool -} - -// ErrMuxClosed is returned when Posting on a closed TypeMux. -var ErrMuxClosed = errors.New("event: mux closed") - -// Subscribe creates a subscription for events of the given types. The -// subscription's channel is closed when it is unsubscribed -// or the mux is closed. -func (mux *TypeMux) Subscribe(types ...interface{}) Subscription { - sub := newsub(mux) - mux.mutex.Lock() - defer mux.mutex.Unlock() - if mux.stopped { - // set the status to closed so that calling Unsubscribe after this - // call will short curuit - sub.closed = true - close(sub.postC) - } else { - if mux.subm == nil { - mux.subm = make(map[reflect.Type][]*muxsub) - } - for _, t := range types { - rtyp := reflect.TypeOf(t) - oldsubs := mux.subm[rtyp] - if find(oldsubs, sub) != -1 { - panic(fmt.Sprintf("event: duplicate type %s in Subscribe", rtyp)) - } - subs := make([]*muxsub, len(oldsubs)+1) - copy(subs, oldsubs) - subs[len(oldsubs)] = sub - mux.subm[rtyp] = subs - } - } - return sub -} - -// Post sends an event to all receivers registered for the given type. -// It returns ErrMuxClosed if the mux has been stopped. -func (mux *TypeMux) Post(ev interface{}) error { - event := &Event{ - Time: time.Now(), - Data: ev, - } - rtyp := reflect.TypeOf(ev) - mux.mutex.RLock() - if mux.stopped { - mux.mutex.RUnlock() - return ErrMuxClosed - } - subs := mux.subm[rtyp] - mux.mutex.RUnlock() - for _, sub := range subs { - sub.deliver(event) - } - return nil -} - -// Stop closes a mux. The mux can no longer be used. -// Future Post calls will fail with ErrMuxClosed. -// Stop blocks until all current deliveries have finished. -func (mux *TypeMux) Stop() { - mux.mutex.Lock() - for _, subs := range mux.subm { - for _, sub := range subs { - sub.closewait() - } - } - mux.subm = nil - mux.stopped = true - mux.mutex.Unlock() -} - -func (mux *TypeMux) del(s *muxsub) { - mux.mutex.Lock() - for typ, subs := range mux.subm { - if pos := find(subs, s); pos >= 0 { - if len(subs) == 1 { - delete(mux.subm, typ) - } else { - mux.subm[typ] = posdelete(subs, pos) - } - } - } - s.mux.mutex.Unlock() -} - -func find(slice []*muxsub, item *muxsub) int { - for i, v := range slice { - if v == item { - return i - } - } - return -1 -} - -func posdelete(slice []*muxsub, pos int) []*muxsub { - news := make([]*muxsub, len(slice)-1) - copy(news[:pos], slice[:pos]) - copy(news[pos:], slice[pos+1:]) - return news -} - -type muxsub struct { - mux *TypeMux - created time.Time - closeMu sync.Mutex - closing chan struct{} - closed bool - - // these two are the same channel. they are stored separately so - // postC can be set to nil without affecting the return value of - // Chan. - postMu sync.RWMutex - readC <-chan *Event - postC chan<- *Event -} - -func newsub(mux *TypeMux) *muxsub { - c := make(chan *Event) - return &muxsub{ - mux: mux, - created: time.Now(), - readC: c, - postC: c, - closing: make(chan struct{}), - } -} - -func (s *muxsub) Chan() <-chan *Event { - return s.readC -} - -func (s *muxsub) Unsubscribe() { - s.mux.del(s) - s.closewait() -} - -func (s *muxsub) closewait() { - s.closeMu.Lock() - defer s.closeMu.Unlock() - if s.closed { - return - } - close(s.closing) - s.closed = true - - s.postMu.Lock() - close(s.postC) - s.postC = nil - s.postMu.Unlock() -} - -func (s *muxsub) deliver(event *Event) { - // Short circuit delivery if stale event - if s.created.After(event.Time) { - return - } - // Otherwise deliver the event - s.postMu.RLock() - defer s.postMu.RUnlock() - - select { - case s.postC <- event: - case <-s.closing: - } -} diff --git a/event_new/event_test.go b/event_new/event_test.go deleted file mode 100644 index fcdb0b1cdda1ed5baf49c55280beed73c92b34f7..0000000000000000000000000000000000000000 --- a/event_new/event_test.go +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// This code is ported over into Eris-RT from Go-Ethereum and further adapted, -// with many thanks to the Ethereum foundation and the Go-Ethereum team. - -package event - -import ( - "math/rand" - "sync" - "testing" - "time" -) - -type testEvent int - -func TestSubCloseUnsub(t *testing.T) { - // the point of this test is **not** to panic - var mux TypeMux - mux.Stop() - sub := mux.Subscribe(int(0)) - sub.Unsubscribe() -} - -func TestSub(t *testing.T) { - mux := new(TypeMux) - defer mux.Stop() - - sub := mux.Subscribe(testEvent(0)) - go func() { - if err := mux.Post(testEvent(5)); err != nil { - t.Errorf("Post returned unexpected error: %v", err) - } - }() - ev := <-sub.Chan() - - if ev.Data.(testEvent) != testEvent(5) { - t.Errorf("Got %v (%T), expected event %v (%T)", - ev, ev, testEvent(5), testEvent(5)) - } -} - -func TestMuxErrorAfterStop(t *testing.T) { - mux := new(TypeMux) - mux.Stop() - - sub := mux.Subscribe(testEvent(0)) - if _, isopen := <-sub.Chan(); isopen { - t.Errorf("subscription channel was not closed") - } - if err := mux.Post(testEvent(0)); err != ErrMuxClosed { - t.Errorf("Post error mismatch, got: %s, expected: %s", err, ErrMuxClosed) - } -} - -func TestUnsubscribeUnblockPost(t *testing.T) { - mux := new(TypeMux) - defer mux.Stop() - - sub := mux.Subscribe(testEvent(0)) - unblocked := make(chan bool) - go func() { - mux.Post(testEvent(5)) - unblocked <- true - }() - - select { - case <-unblocked: - t.Errorf("Post returned before Unsubscribe") - default: - sub.Unsubscribe() - <-unblocked - } -} - -func TestSubscribeDuplicateType(t *testing.T) { - mux := new(TypeMux) - expected := "event: duplicate type event.testEvent in Subscribe" - - defer func() { - err := recover() - if err == nil { - t.Errorf("Subscribe didn't panic for duplicate type") - } else if err != expected { - t.Errorf("panic mismatch: got %#v, expected %#v", err, expected) - } - }() - mux.Subscribe(testEvent(1), testEvent(2)) -} - -func TestMuxConcurrent(t *testing.T) { - rand.Seed(time.Now().Unix()) - mux := new(TypeMux) - defer mux.Stop() - - recv := make(chan int) - poster := func() { - for { - err := mux.Post(testEvent(0)) - if err != nil { - return - } - } - } - sub := func(i int) { - time.Sleep(time.Duration(rand.Intn(99)) * time.Millisecond) - sub := mux.Subscribe(testEvent(0)) - <-sub.Chan() - sub.Unsubscribe() - recv <- i - } - - go poster() - go poster() - go poster() - nsubs := 1000 - for i := 0; i < nsubs; i++ { - go sub(i) - } - - // wait until everyone has been served - counts := make(map[int]int, nsubs) - for i := 0; i < nsubs; i++ { - counts[<-recv]++ - } - for i, count := range counts { - if count != 1 { - t.Errorf("receiver %d called %d times, expected only 1 call", i, count) - } - } -} - -func emptySubscriber(mux *TypeMux, types ...interface{}) { - s := mux.Subscribe(testEvent(0)) - go func() { - for _ = range s.Chan() { - } - }() -} - -func BenchmarkPost3(b *testing.B) { - var mux = new(TypeMux) - defer mux.Stop() - emptySubscriber(mux, testEvent(0)) - emptySubscriber(mux, testEvent(0)) - emptySubscriber(mux, testEvent(0)) - - for i := 0; i < b.N; i++ { - mux.Post(testEvent(0)) - } -} - -func BenchmarkPostConcurrent(b *testing.B) { - var mux = new(TypeMux) - defer mux.Stop() - emptySubscriber(mux, testEvent(0)) - emptySubscriber(mux, testEvent(0)) - emptySubscriber(mux, testEvent(0)) - - var wg sync.WaitGroup - poster := func() { - for i := 0; i < b.N; i++ { - mux.Post(testEvent(0)) - } - wg.Done() - } - wg.Add(5) - for i := 0; i < 5; i++ { - go poster() - } - wg.Wait() -} - -// for comparison -func BenchmarkChanSend(b *testing.B) { - c := make(chan interface{}) - closed := make(chan struct{}) - go func() { - for _ = range c { - } - }() - - for i := 0; i < b.N; i++ { - select { - case c <- i: - case <-closed: - } - } -} diff --git a/event_new/example_test.go b/event_new/example_test.go deleted file mode 100644 index 439589021747fcbd53b6fb2663b9b6d6547c2f65..0000000000000000000000000000000000000000 --- a/event_new/example_test.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// This code is ported over into Eris-RT from Go-Ethereum and further adapted, -// with many thanks to the Ethereum foundation and the Go-Ethereum team. - -package event - -import "fmt" - -func ExampleTypeMux() { - type someEvent struct{ I int } - type otherEvent struct{ S string } - type yetAnotherEvent struct{ X, Y int } - - var mux TypeMux - - // Start a subscriber. - done := make(chan struct{}) - sub := mux.Subscribe(someEvent{}, otherEvent{}) - go func() { - for event := range sub.Chan() { - fmt.Printf("Received: %#v\n", event.Data) - } - fmt.Println("done") - close(done) - }() - - // Post some events. - mux.Post(someEvent{5}) - mux.Post(yetAnotherEvent{X: 3, Y: 4}) - mux.Post(someEvent{6}) - mux.Post(otherEvent{"whoa"}) - - // Stop closes all subscription channels. - // The subscriber goroutine will print "done" - // and exit. - mux.Stop() - - // Wait for subscriber to return. - <-done - - // Output: - // Received: event.someEvent{I:5} - // Received: event.someEvent{I:6} - // Received: event.otherEvent{S:"whoa"} - // done -} diff --git a/event_new/filter/filter.go b/event_new/filter/filter.go deleted file mode 100644 index 9742057dd9a16ee100c95bc86b16a715d654b219..0000000000000000000000000000000000000000 --- a/event_new/filter/filter.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// This code is ported over into Eris-RT from Go-Ethereum and further adapted, -// with many thanks to the Ethereum foundation and the Go-Ethereum team. - -// Package filter implements event filters. -package filter - -import "reflect" - -type Filter interface { - Compare(Filter) bool - Trigger(data interface{}) -} - -type FilterEvent struct { - filter Filter - data interface{} -} - -type Filters struct { - id int - watchers map[int]Filter - ch chan FilterEvent - - quit chan struct{} -} - -func New() *Filters { - return &Filters{ - ch: make(chan FilterEvent), - watchers: make(map[int]Filter), - quit: make(chan struct{}), - } -} - -func (self *Filters) Start() { - go self.loop() -} - -func (self *Filters) Stop() { - close(self.quit) -} - -func (self *Filters) Notify(filter Filter, data interface{}) { - self.ch <- FilterEvent{filter, data} -} - -func (self *Filters) Install(watcher Filter) int { - self.watchers[self.id] = watcher - self.id++ - - return self.id - 1 -} - -func (self *Filters) Uninstall(id int) { - delete(self.watchers, id) -} - -func (self *Filters) loop() { -out: - for { - select { - case <-self.quit: - break out - case event := <-self.ch: - for _, watcher := range self.watchers { - if reflect.TypeOf(watcher) == reflect.TypeOf(event.filter) { - if watcher.Compare(event.filter) { - watcher.Trigger(event.data) - } - } - } - } - } -} - -func (self *Filters) Match(a, b Filter) bool { - return reflect.TypeOf(a) == reflect.TypeOf(b) && a.Compare(b) -} - -func (self *Filters) Get(i int) Filter { - return self.watchers[i] -} diff --git a/event_new/filter/filter_test.go b/event_new/filter/filter_test.go deleted file mode 100644 index c70d1ecce6e8b9c0fb120c8eb2d6f83d049cf48e..0000000000000000000000000000000000000000 --- a/event_new/filter/filter_test.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// This code is ported over into Eris-RT from Go-Ethereum and further adapted, -// with many thanks to the Ethereum foundation and the Go-Ethereum team. - -package filter - -import ( - "testing" - "time" -) - -// Simple test to check if baseline matching/mismatching filtering works. -func TestFilters(t *testing.T) { - fm := New() - fm.Start() - - // Register two filters to catch posted data - first := make(chan struct{}) - fm.Install(Generic{ - Str1: "hello", - Fn: func(data interface{}) { - first <- struct{}{} - }, - }) - second := make(chan struct{}) - fm.Install(Generic{ - Str1: "hello1", - Str2: "hello", - Fn: func(data interface{}) { - second <- struct{}{} - }, - }) - // Post an event that should only match the first filter - fm.Notify(Generic{Str1: "hello"}, true) - fm.Stop() - - // Ensure only the mathcing filters fire - select { - case <-first: - case <-time.After(100 * time.Millisecond): - t.Error("matching filter timed out") - } - select { - case <-second: - t.Error("mismatching filter fired") - case <-time.After(100 * time.Millisecond): - } -} diff --git a/event_new/filter/generic_filter.go b/event_new/filter/generic_filter.go deleted file mode 100644 index 6b475b97214502d5646c2ab7ccb586f33b3b8484..0000000000000000000000000000000000000000 --- a/event_new/filter/generic_filter.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// This code is ported over into Eris-RT from Go-Ethereum and further adapted, -// with many thanks to the Ethereum foundation and the Go-Ethereum team. - -package filter - -type Generic struct { - Str1, Str2, Str3 string - Data map[string]struct{} - - Fn func(data interface{}) -} - -// self = registered, f = incoming -func (self Generic) Compare(f Filter) bool { - var strMatch, dataMatch = true, true - - filter := f.(Generic) - if (len(self.Str1) > 0 && filter.Str1 != self.Str1) || - (len(self.Str2) > 0 && filter.Str2 != self.Str2) || - (len(self.Str3) > 0 && filter.Str3 != self.Str3) { - strMatch = false - } - - for k, _ := range self.Data { - if _, ok := filter.Data[k]; !ok { - return false - } - } - - return strMatch && dataMatch -} - -func (self Generic) Trigger(data interface{}) { - self.Fn(data) -} diff --git a/files/files.go b/files/files.go index aa9e59c83a11c980383e50198125fde577dd59cf..a11c8a62f145ba42813c5086713b9241f9212e21 100644 --- a/files/files.go +++ b/files/files.go @@ -1,4 +1,18 @@ // Cross-platform file utils. +// Copyright 2017 Monax Industries Limited +// +// 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 files import ( diff --git a/files/files_test.go b/files/files_test.go index 16943df7f53d6f5e899e89b26c224d68aa71705c..1cf51762f6c7c8b3ae3d3977026318c73341b8f7 100644 --- a/files/files_test.go +++ b/files/files_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 files import ( diff --git a/files/log.go b/files/log.go index a18f6b6a6ec7420d469269b33832a2e5cc277a43..3914c6c7b80df67fb9ad47a2f9e3714a81a4d19a 100644 --- a/files/log.go +++ b/files/log.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 files import ( diff --git a/files/posix.go b/files/posix.go index e3dcb079ddcb0fc2d7a86b428317da62d7a5cac8..037f40dd7cd12c5c679e89be35661b2029e7e5d2 100644 --- a/files/posix.go +++ b/files/posix.go @@ -1,5 +1,19 @@ // +build !windows +// Copyright 2017 Monax Industries Limited +// +// 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 files import "os" diff --git a/files/windows.go b/files/windows.go index 495dd30386412cfde0ffe73d8d4c22ed3558a3a6..27a7fd84a447a8843730ac517bc9605832cb39d0 100644 --- a/files/windows.go +++ b/files/windows.go @@ -1,5 +1,19 @@ // +build windows +// Copyright 2017 Monax Industries Limited +// +// 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 files import ( diff --git a/genesis/gen_test.go b/genesis/gen_test.go index 30d5f9c511df7efbd372c6a44814b1c0d64070c8..3a55eea7df1cbbba038cfb07be248dc383f5c889 100644 --- a/genesis/gen_test.go +++ b/genesis/gen_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 genesis import ( @@ -6,6 +20,7 @@ import ( "os" "path/filepath" "testing" + "time" ) // set the chain ID @@ -149,7 +164,8 @@ func TestKnownCSV(t *testing.T) { } // create the genesis file - genesisFileWritten, err := GenerateKnown(chainID, accountsCSVpath, validatorsCSVpath) + // NOTE: [ben] set time to zero time, "genesis_time": "0001-01-01T00:00:00.000Z" + genesisFileWritten, err := generateKnownWithTime(chainID, accountsCSVpath, validatorsCSVpath, time.Time{}) if err != nil { t.Fatal(err) } diff --git a/genesis/genesis.go b/genesis/genesis.go new file mode 100644 index 0000000000000000000000000000000000000000..3ca287e55bc6c214a7032413e665fb85103a1d79 --- /dev/null +++ b/genesis/genesis.go @@ -0,0 +1,84 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 genesis + +import ( + "bytes" + "encoding/json" + "time" + + ptypes "github.com/eris-ltd/eris-db/permission/types" + wire "github.com/tendermint/go-wire" +) + +// MakeGenesisDocFromAccounts takes a chainName and a slice of pointers to GenesisAccount, +// and a slice of pointers to GenesisValidator to construct a GenesisDoc, or returns an error on +// failure. In particular MakeGenesisDocFromAccount uses the local time as a +// timestamp for the GenesisDoc. +func MakeGenesisDocFromAccounts(chainName string, accounts []*GenesisAccount, + validators []*GenesisValidator) (GenesisDoc, error) { + + // TODO: assert valid accounts and validators + // TODO: [ben] expose setting global permissions + globalPermissions := ptypes.DefaultAccountPermissions.Clone() + genesisParameters := &GenesisParams{ + GlobalPermissions: &globalPermissions, + } + // copy slice of pointers to accounts into slice of accounts + accountsCopy := make([]GenesisAccount, len(accounts)) + for i, genesisAccount := range accounts { + accountsCopy[i] = genesisAccount.Clone() + } + // copy slice of pointers to validators into slice of validators + validatorsCopy := make([]GenesisValidator, len(validators)) + for i, genesisValidator := range validators { + genesisValidatorCopy, err := genesisValidator.Clone() + if err != nil { + return GenesisDoc{}, err + } + validatorsCopy[i] = genesisValidatorCopy + } + genesisDoc := GenesisDoc{ + GenesisTime: time.Now(), + // TODO: this needs to be corrected for ChainName, and ChainId + // is the derived hash from the GenesisDoc serialised bytes + ChainID: chainName, + Params: genesisParameters, + Accounts: accountsCopy, + Validators: validatorsCopy, + } + return genesisDoc, nil +} + +// GetGenesisFileBytes returns the JSON (not-yet) canonical bytes for a given +// GenesisDoc or an error. In a first rewrite, rely on go-wire +// for the JSON serialisation with type-bytes. +func GetGenesisFileBytes(genesisDoc *GenesisDoc) ([]byte, error) { + + // TODO: write JSON in canonical order + var err error + buffer, n := new(bytes.Buffer), new(int) + // write JSON with go-wire type-bytes (for public keys) + wire.WriteJSON(genesisDoc, buffer, n, &err) + if err != nil { + return nil, err + } + // rewrite buffer with indentation + indentedBuffer := new(bytes.Buffer) + if err := json.Indent(indentedBuffer, buffer.Bytes(), "", "\t"); err != nil { + return nil, err + } + return indentedBuffer.Bytes(), nil +} diff --git a/genesis/make_genesis_file.go b/genesis/make_genesis_file.go index c4324366ccf4f1c6195684ce32c59592ddc37712..a4dce67bf1f200c23da9055ee6ff1cc028aecc12 100644 --- a/genesis/make_genesis_file.go +++ b/genesis/make_genesis_file.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 genesis import ( @@ -8,6 +22,7 @@ import ( "fmt" "os" "strconv" + "time" ptypes "github.com/eris-ltd/eris-db/permission/types" "github.com/eris-ltd/eris-db/util" @@ -17,9 +32,44 @@ import ( ) //------------------------------------------------------------------------------------ -// core functions +// interface functions that are consumed by monax tooling +// TODO: [ben] these interfaces will be deprecated from v0.17 func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, error) { + return generateKnownWithTime(chainID, accountsPathCSV, validatorsPathCSV, + // set the timestamp for the genesis + time.Now()) +} + +//------------------------------------------------------------------------------------ +// interface functions that are consumed by monax tooling + +func GenerateGenesisFileBytes(chainName string, genesisAccounts []*GenesisAccount, + genesisValidators []*GenesisValidator) ([]byte, error) { + genesisDoc, err := MakeGenesisDocFromAccounts(chainName, genesisAccounts, genesisValidators) + + buf, buf2, n := new(bytes.Buffer), new(bytes.Buffer), new(int) + wire.WriteJSON(genesisDoc, buf, n, &err) + if err != nil { + return nil, err + } + if err := json.Indent(buf2, buf.Bytes(), "", "\t"); err != nil { + return nil, err + } + + return buf2.Bytes(), nil +} + +//------------------------------------------------------------------------------------ +// core functions that provide functionality for monax tooling in v0.16 + +// GenerateKnownWithTime takes chainId, an accounts and validators CSV filepath +// and a timestamp to generate the string of `genesis.json` +// NOTE: [ben] is introduced as technical debt to preserve the signature +// of GenerateKnown but in order to introduce the timestamp gradually +// This will be deprecated in v0.17 +func generateKnownWithTime(chainID, accountsPathCSV, validatorsPathCSV string, + genesisTime time.Time) (string, error) { var genDoc *GenesisDoc // TODO [eb] eliminate reading priv_val ... [zr] where? @@ -37,7 +87,7 @@ func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, return "", err } - genDoc = newGenDoc(chainID, len(pubkeys), len(pubkeysA)) + genDoc = newGenDoc(chainID, genesisTime, len(pubkeys), len(pubkeysA)) for i, pk := range pubkeys { genDocAddValidator(genDoc, pk, amts[i], names[i], perms[i], setbits[i], i) } @@ -60,10 +110,10 @@ func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, //----------------------------------------------------------------------------- // gendoc convenience functions -func newGenDoc(chainID string, nVal, nAcc int) *GenesisDoc { +func newGenDoc(chainID string, genesisTime time.Time, nVal, nAcc int) *GenesisDoc { genDoc := GenesisDoc{ - ChainID: chainID, - // GenesisTime: time.Now(), + ChainID: chainID, + GenesisTime: genesisTime, } genDoc.Accounts = make([]GenesisAccount, nAcc) genDoc.Validators = make([]GenesisValidator, nVal) diff --git a/genesis/maker.go b/genesis/maker.go new file mode 100644 index 0000000000000000000000000000000000000000..707d8150ee17bbe5c4f8191ba3e2d8018de7ddcd --- /dev/null +++ b/genesis/maker.go @@ -0,0 +1,84 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 genesis + +import ( + "fmt" + + ptypes "github.com/eris-ltd/eris-db/permission/types" + + "github.com/tendermint/go-crypto" +) + +const ( + PublicKeyEd25519ByteLength int = 32 + PublicKeySecp256k1ByteLength int = 64 +) + +// NewGenesisAccount returns a new GenesisAccount +func NewGenesisAccount(address []byte, amount int64, name string, + permissions *ptypes.AccountPermissions) *GenesisAccount { + return &GenesisAccount{ + Address: address, + Amount: amount, + Name: name, + Permissions: permissions, + } +} + +func NewGenesisValidator(amount int64, name string, unbondToAddress []byte, + unbondAmount int64, keyType string, publicKeyBytes []byte) (*GenesisValidator, error) { + // convert the key bytes into a typed fixed size byte array + var typedPublicKeyBytes []byte + switch keyType { + case "ed25519": + // TODO: [ben] functionality and checks need to be inherit in the type + if len(publicKeyBytes) != PublicKeyEd25519ByteLength { + return nil, fmt.Errorf("Invalid length provided for ed25519 public key (len %v)", + len(publicKeyBytes)) + } + // ed25519 has type byte 0x01 + typedPublicKeyBytes = make([]byte, PublicKeyEd25519ByteLength+1) + // prepend type byte to public key + typedPublicKeyBytes = append([]byte{crypto.PubKeyTypeEd25519}, publicKeyBytes...) + case "secp256k1": + if len(publicKeyBytes) != PublicKeySecp256k1ByteLength { + return nil, fmt.Errorf("Invalid length provided for secp256k1 public key (len %v)", + len(publicKeyBytes)) + } + // secp256k1 has type byte 0x02 + typedPublicKeyBytes = make([]byte, PublicKeySecp256k1ByteLength+1) + // prepend type byte to public key + typedPublicKeyBytes = append([]byte{crypto.PubKeyTypeSecp256k1}, publicKeyBytes...) + default: + return nil, fmt.Errorf("Unsupported key type (%s)", keyType) + } + newPublicKey, err := crypto.PubKeyFromBytes(typedPublicKeyBytes) + if err != nil { + return nil, err + } + // ability to unbond to multiple accounts currently unused + var unbondTo []BasicAccount + + return &GenesisValidator{ + PubKey: newPublicKey, + Amount: unbondAmount, + Name: name, + UnbondTo: append(unbondTo, BasicAccount{ + Address: unbondToAddress, + Amount: unbondAmount, + }), + }, nil +} diff --git a/genesis/types.go b/genesis/types.go index d03e6197645b67ab9f306a9d71106a2ab0d7b338..c962a3c316d406f4e1b2cac7fde1bab14c37b2ea 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 genesis import ( @@ -6,6 +20,7 @@ import ( "time" ptypes "github.com/eris-ltd/eris-db/permission/types" + "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire" ) @@ -37,6 +52,19 @@ type GenesisValidator struct { UnbondTo []BasicAccount `json:"unbond_to"` } +// GenesisPrivateValidator marshals the state of the private +// validator for the purpose of Genesis creation; and hence +// is defined in genesis and not under consensus, where +// PrivateValidator (currently inherited from Tendermint) is. +type GenesisPrivateValidator struct { + Address string `json:"address"` + PubKey []interface{} `json:"pub_key"` + PrivKey []interface{} `json:"priv_key"` + LastHeight int64 `json:"last_height"` + LastRound int64 `json:"last_round"` + LastStep int64 `json:"last_step"` +} + type GenesisParams struct { GlobalPermissions *ptypes.AccountPermissions `json:"global_permissions"` } @@ -65,3 +93,65 @@ func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) { } return } + +//------------------------------------------------------------ +// Methods for genesis types +// NOTE: breaks formatting convention +// TODO: split each genesis type in its own file definition + +//------------------------------------------------------------ +// GenesisAccount methods + +// Clone clones the genesis account +func (genesisAccount *GenesisAccount) Clone() GenesisAccount { + // clone the address + addressClone := make([]byte, len(genesisAccount.Address)) + copy(addressClone, genesisAccount.Address) + // clone the account permissions + accountPermissionsClone := genesisAccount.Permissions.Clone() + return GenesisAccount{ + Address: addressClone, + Amount: genesisAccount.Amount, + Name: genesisAccount.Name, + Permissions: &accountPermissionsClone, + } +} + +//------------------------------------------------------------ +// GenesisValidator methods + +// Clone clones the genesis validator +func (genesisValidator *GenesisValidator) Clone() (GenesisValidator, error) { + if genesisValidator == nil { + return GenesisValidator{}, fmt.Errorf("Cannot clone nil GenesisValidator.") + } + if genesisValidator.PubKey == nil { + return GenesisValidator{}, fmt.Errorf("Invalid GenesisValidator %s with nil public key.", + genesisValidator.Name) + } + // clone the addresses to unbond to + unbondToClone := make([]BasicAccount, len(genesisValidator.UnbondTo)) + for i, basicAccount := range genesisValidator.UnbondTo { + unbondToClone[i] = basicAccount.Clone() + } + return GenesisValidator{ + PubKey: genesisValidator.PubKey, + Amount: genesisValidator.Amount, + Name: genesisValidator.Name, + UnbondTo: unbondToClone, + }, nil +} + +//------------------------------------------------------------ +// BasicAccount methods + +// Clone clones the basic account +func (basicAccount *BasicAccount) Clone() BasicAccount { + // clone the address + addressClone := make([]byte, len(basicAccount.Address)) + copy(addressClone, basicAccount.Address) + return BasicAccount{ + Address: addressClone, + Amount: basicAccount.Amount, + } +} diff --git a/keys/key_client.go b/keys/key_client.go index 2431bc643500016bc5859d91c8a48955d451dbf2..edbc451123db1c069033cbce1cad4a1d0b2135b1 100644 --- a/keys/key_client.go +++ b/keys/key_client.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 keys diff --git a/keys/key_client_util.go b/keys/key_client_util.go index 5fd1cbce41f55d1348584aeb29d55dacf7fcc1d8..b59c61f6b37a9a1ffa2b21f6b7982eecd7f3fb12 100644 --- a/keys/key_client_util.go +++ b/keys/key_client_util.go @@ -1,21 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// version provides the current Eris-DB version and a VersionIdentifier -// for the modules to identify their version with. +// Copyright 2017 Monax Industries Limited +// +// 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 keys diff --git a/keys/mock/key_client_mock.go b/keys/mock/key_client_mock.go index ef9cca8612a535011da62185af3e0a72fa8a5170..d1ae1bd0917124025d79d6f1c5f7b0d109d9d669 100644 --- a/keys/mock/key_client_mock.go +++ b/keys/mock/key_client_mock.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 mock diff --git a/license.md b/license.md index 9cecc1d4669ee8af2ca727a5d8cde10cd8b2d7cc..d9a10c0d8e868ebf8da0b3dc95bb0be634c34bfe 100644 --- a/license.md +++ b/license.md @@ -1,674 +1,176 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -<http://www.gnu.org/licenses/>. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -<http://www.gnu.org/philosophy/why-not-lgpl.html>. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/logging/adapters/logrus/logrus.go b/logging/adapters/logrus/logrus.go index fe974768f69179c01c1d3a5b4b6334ba7d6ce7d2..84b6837188e6c6712ef05461227b658372ccd0bb 100644 --- a/logging/adapters/logrus/logrus.go +++ b/logging/adapters/logrus/logrus.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 adapters import ( diff --git a/logging/adapters/stdlib/capture.go b/logging/adapters/stdlib/capture.go index b5fadacc9d87cd3f71a8a603d29040f8dc4d8921..3c8a2a88e14b4199b548c6cea441c67d3d1a90e5 100644 --- a/logging/adapters/stdlib/capture.go +++ b/logging/adapters/stdlib/capture.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 stdlib import ( diff --git a/logging/adapters/tendermint_log15/capture.go b/logging/adapters/tendermint_log15/capture.go index afc5d29eedcc61aacbbe8318775da50e74be0468..64f5a139da1860ffc929c7e49c617be51099649b 100644 --- a/logging/adapters/tendermint_log15/capture.go +++ b/logging/adapters/tendermint_log15/capture.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 adapters import ( diff --git a/logging/adapters/tendermint_log15/convert.go b/logging/adapters/tendermint_log15/convert.go index f7be8420866a67a987afb39f84b2e93cea849018..f1668b262ab0dac75948274da43c97c52d12b0e3 100644 --- a/logging/adapters/tendermint_log15/convert.go +++ b/logging/adapters/tendermint_log15/convert.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 adapters import ( diff --git a/logging/config.go b/logging/config.go index b43b1b5545ba47586cb3e61a01589bac4de564c0..5123b93695f9ee60ecb38e50ef58ad040fd6780c 100644 --- a/logging/config.go +++ b/logging/config.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 logging type ( diff --git a/logging/convention.go b/logging/convention.go index 0f5d3372c13bb9903ea1db88ef24035bfc33a9b5..8dc5b05da97bc2b9bf267ed55e281a47989f32f6 100644 --- a/logging/convention.go +++ b/logging/convention.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 logging import ( diff --git a/logging/lifecycle/lifecycle.go b/logging/lifecycle/lifecycle.go index ce0faef40ace4decfb9f71a09126d3d22ce4e41d..81f6a20df8e14b0265ba7017b7115a413cd54863 100644 --- a/logging/lifecycle/lifecycle.go +++ b/logging/lifecycle/lifecycle.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 lifecycle // No package in ./logging/... should depend on lifecycle diff --git a/logging/loggers/channel_logger.go b/logging/loggers/channel_logger.go index 20e824ef804deaf9de64266d94c1ef8338d47344..1bacfa44697847389ab8b689f0a672cb3a3fa53b 100644 --- a/logging/loggers/channel_logger.go +++ b/logging/loggers/channel_logger.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/channel_logger_test.go b/logging/loggers/channel_logger_test.go index 14b50fa0edc621761e7f9e78df2c304478a4a31e..0573556e15f70b11ec1163e36ab5435106e612ab 100644 --- a/logging/loggers/channel_logger_test.go +++ b/logging/loggers/channel_logger_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/eris_format_logger.go b/logging/loggers/eris_format_logger.go index 20cdd8d653ad1ef09076c24e547d7f0f89e58297..aea07254d4d0356620a40919f8caad7165bb3e43 100644 --- a/logging/loggers/eris_format_logger.go +++ b/logging/loggers/eris_format_logger.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/info_trace_logger.go b/logging/loggers/info_trace_logger.go index 6cbdcee6bd9f0aeb2d7965465835f304226eb42a..e127e10feef184c68b26fa2fe15131e6d17da3ea 100644 --- a/logging/loggers/info_trace_logger.go +++ b/logging/loggers/info_trace_logger.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/info_trace_logger_test.go b/logging/loggers/info_trace_logger_test.go index 505f2606badbeb178f9046982a6d130030225456..1717455401d50c787be69f7a9ee99991c3836366 100644 --- a/logging/loggers/info_trace_logger_test.go +++ b/logging/loggers/info_trace_logger_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/logging_test.go b/logging/loggers/logging_test.go index 78166fc91ca74989abeb7e08daf793dce10595a2..103d8ddf7c295cd5749e66ea5697c4eaa55791cf 100644 --- a/logging/loggers/logging_test.go +++ b/logging/loggers/logging_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import "errors" diff --git a/logging/loggers/multiple_channel_logger.go b/logging/loggers/multiple_channel_logger.go index 47ee96065ae4d8b04a3130f5903bc192ea341aed..2e2e344f44bc1a69f7c53ed3608f257a09c9304c 100644 --- a/logging/loggers/multiple_channel_logger.go +++ b/logging/loggers/multiple_channel_logger.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/multiple_channel_logger_test.go b/logging/loggers/multiple_channel_logger_test.go index db8f5013a13c636af96c2791d0ee5e00a38695fc..a140420433a6aef95879457e97db8bdbeff7b5f4 100644 --- a/logging/loggers/multiple_channel_logger_test.go +++ b/logging/loggers/multiple_channel_logger_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/multiple_output_logger.go b/logging/loggers/multiple_output_logger.go index 9f3cb5326aa1a98d0f3fcfad6462051965749064..89ae50a978964758ead7891c5e79ece832cd87ce 100644 --- a/logging/loggers/multiple_output_logger.go +++ b/logging/loggers/multiple_output_logger.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/multiple_output_logger_test.go b/logging/loggers/multiple_output_logger_test.go index 786c60064947d3475c60275f45140ce39edde199..4f606376af8c44d8441bbb33d6d49d322138a833 100644 --- a/logging/loggers/multiple_output_logger_test.go +++ b/logging/loggers/multiple_output_logger_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/vector_valued_logger.go b/logging/loggers/vector_valued_logger.go index b8963db13f61a9e02fdf5273010d9f4910d51009..fa59cdbfaaf48b260cf3b77d592cdad97aa2280d 100644 --- a/logging/loggers/vector_valued_logger.go +++ b/logging/loggers/vector_valued_logger.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/loggers/vector_valued_logger_test.go b/logging/loggers/vector_valued_logger_test.go index d6bc54ebdcfb76d0a7b3f20606828d458e6a5d13..157f5bc08fc162d557b295d960aae359a024130c 100644 --- a/logging/loggers/vector_valued_logger_test.go +++ b/logging/loggers/vector_valued_logger_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 loggers import ( diff --git a/logging/metadata.go b/logging/metadata.go index d645699902e9a6b9a334390a8824c774aac5a4e6..258ca733c749698d85bc26fca949bc5eed0d5a2b 100644 --- a/logging/metadata.go +++ b/logging/metadata.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 logging import ( diff --git a/logging/structure/structure.go b/logging/structure/structure.go index a104e8c9dad8cc5ec7dc67880557e5593f071111..43a55df87f7cd2f93a859dce5980ada59964e843 100644 --- a/logging/structure/structure.go +++ b/logging/structure/structure.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 structure import ( diff --git a/logging/structure/structure_test.go b/logging/structure/structure_test.go index fde15ff4ae247a02166d91fe7850328c01417e33..bbdd0895f348a8c6ceb99dca26470dce1b34e4ca 100644 --- a/logging/structure/structure_test.go +++ b/logging/structure/structure_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 structure import ( diff --git a/logging/terminal.go b/logging/terminal.go index e8eea7d8107484f1f5bd79a745f042e77fa49e8f..8a2be393e4ba61152ac58f9d872b5ada94ab2a68 100644 --- a/logging/terminal.go +++ b/logging/terminal.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 logging import ( diff --git a/manager/config.go b/manager/config.go index 28c84e21dac88ac0b6763eddbca1c7236e701519..827d25ed5b1fa036628f3b6fc429a12029dada6f 100644 --- a/manager/config.go +++ b/manager/config.go @@ -1,21 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// version provides the current Eris-DB version and a VersionIdentifier -// for the modules to identify their version with. +// Copyright 2017 Monax Industries Limited +// +// 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 manager diff --git a/manager/eris-mint/accounts.go b/manager/eris-mint/accounts.go index 58a09b0e765c143dba2595fa4c35d660ad59b40d..9134162940f5f891f886330f71fb3c45ca027c60 100644 --- a/manager/eris-mint/accounts.go +++ b/manager/eris-mint/accounts.go @@ -1,22 +1,21 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package erismint // Accounts is part of the pipe for ErisMint and provides the implementation // for the pipe to call into the ErisMint application -package erismint import ( "bytes" @@ -24,12 +23,11 @@ import ( "fmt" "sync" - tendermint_common "github.com/tendermint/go-common" - account "github.com/eris-ltd/eris-db/account" core_types "github.com/eris-ltd/eris-db/core/types" definitions "github.com/eris-ltd/eris-db/definitions" event "github.com/eris-ltd/eris-db/event" + word256 "github.com/eris-ltd/eris-db/word256" ) // NOTE [ben] Compiler check to ensure Accounts successfully implements @@ -119,7 +117,7 @@ func (this *accounts) StorageAt(address, key []byte) (*core_types.StorageItem, storageRoot := account.StorageRoot storageTree := state.LoadStorage(storageRoot) - _, value, _ := storageTree.Get(tendermint_common.LeftPadWord256(key).Bytes()) + _, value, _ := storageTree.Get(word256.LeftPadWord256(key).Bytes()) if value == nil { return &core_types.StorageItem{key, []byte{}}, nil } diff --git a/manager/eris-mint/eris-mint.go b/manager/eris-mint/eris-mint.go index 29050723ae9e89850b0ebbb91d432591ffdb4ef1..fe3948e12feb8a29536ea2865632012781255157 100644 --- a/manager/eris-mint/eris-mint.go +++ b/manager/eris-mint/eris-mint.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 erismint @@ -168,13 +166,13 @@ func (app *ErisMint) Commit() (res tmsp.Result) { // flush events to listeners (XXX: note issue with blocking) app.evc.Flush() - // MARMOT: - // set internal time as two seconds per block + // TODO: [ben] over the tendermint 0.6 TMSP interface we have + // no access to the block header implemented; + // On Tendermint v0.8 load the blockheader into the application + // state and remove the fixed 2-"seconds" per block internal clock. + // NOTE: set internal time as two seconds per block app.state.LastBlockTime = app.state.LastBlockTime.Add(time.Duration(2) * time.Second) - fmt.Printf("\n\nMARMOT TIME: %s\n\n", app.state.LastBlockTime) - // MARMOT: appHash := app.state.Hash() - fmt.Printf("\n\nMARMOT COMMIT: %X\n\n", appHash) // return tmsp.NewResultOK(app.state.Hash(), "Success") return tmsp.NewResultOK(appHash, "Success") } diff --git a/manager/eris-mint/eris-mint_test.go b/manager/eris-mint/eris-mint_test.go index 294c34e233db0c260c3a0b3fd5993ad789d56231..b37c89532caeac8ffcaa7346419487bc973f97c8 100644 --- a/manager/eris-mint/eris-mint_test.go +++ b/manager/eris-mint/eris-mint_test.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 erismint diff --git a/manager/eris-mint/evm/abi/types.go b/manager/eris-mint/evm/abi/types.go new file mode 100644 index 0000000000000000000000000000000000000000..40c12f545016703b863a37d89fb9f0812be16e23 --- /dev/null +++ b/manager/eris-mint/evm/abi/types.go @@ -0,0 +1,41 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 abi + +// Ethereum defines types and calling conventions for the ABI +// (application binary interface) here: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI +// We make a start of representing them here + +type Type string + +type Arg struct { + Name string + Type Type +} + +type Return struct { + Name string + Type Type +} + +const ( + // We don't need to be exhaustive here, just make what we used strongly typed + Address Type = "address" + Int Type = "int" + Uint64 Type = "uint64" + Bytes32 Type = "bytes32" + String Type = "string" + Bool Type = "bool" +) diff --git a/manager/eris-mint/evm/common.go b/manager/eris-mint/evm/common.go index 00ab93c775f6b4ba8e29c1cc38eca28a9a7920f2..fbbd4c51a33263669eaf4bc699ddc730a2ce84ba 100644 --- a/manager/eris-mint/evm/common.go +++ b/manager/eris-mint/evm/common.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( diff --git a/manager/eris-mint/evm/test/fake_app_state.go b/manager/eris-mint/evm/fake_app_state.go similarity index 64% rename from manager/eris-mint/evm/test/fake_app_state.go rename to manager/eris-mint/evm/fake_app_state.go index c27e54256fe7ea102ffea6bd3d12431382f1ec52..3c19b0cf27d39df45bae5480ebf40c4ac4898c6e 100644 --- a/manager/eris-mint/evm/test/fake_app_state.go +++ b/manager/eris-mint/evm/fake_app_state.go @@ -1,9 +1,24 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( - . "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + "fmt" + "github.com/eris-ltd/eris-db/manager/eris-mint/evm/sha3" - . "github.com/tendermint/go-common" + . "github.com/eris-ltd/eris-db/word256" ) type FakeAppState struct { @@ -23,7 +38,7 @@ func (fas *FakeAppState) UpdateAccount(account *Account) { func (fas *FakeAppState) RemoveAccount(account *Account) { _, ok := fas.accounts[account.Address.String()] if !ok { - panic(Fmt("Invalid account addr: %X", account.Address)) + panic(fmt.Sprintf("Invalid account addr: %X", account.Address)) } else { // Remove account delete(fas.accounts, account.Address.String()) @@ -41,14 +56,14 @@ func (fas *FakeAppState) CreateAccount(creator *Account) *Account { Nonce: 0, } } else { - panic(Fmt("Invalid account addr: %X", addr)) + panic(fmt.Sprintf("Invalid account addr: %X", addr)) } } func (fas *FakeAppState) GetStorage(addr Word256, key Word256) Word256 { _, ok := fas.accounts[addr.String()] if !ok { - panic(Fmt("Invalid account addr: %X", addr)) + panic(fmt.Sprintf("Invalid account addr: %X", addr)) } value, ok := fas.storage[addr.String()+key.String()] @@ -62,7 +77,7 @@ func (fas *FakeAppState) GetStorage(addr Word256, key Word256) Word256 { func (fas *FakeAppState) SetStorage(addr Word256, key Word256, value Word256) { _, ok := fas.accounts[addr.String()] if !ok { - panic(Fmt("Invalid account addr: %X", addr)) + panic(fmt.Sprintf("Invalid account addr: %X", addr)) } fas.storage[addr.String()+key.String()] = value diff --git a/manager/eris-mint/evm/gas.go b/manager/eris-mint/evm/gas.go index fe4a43d80d5ae2ffddbb75b44f0a5633d70bb43e..9ffc5e56d6d9363aaeabb815d24fdc9dd1b3f602 100644 --- a/manager/eris-mint/evm/gas.go +++ b/manager/eris-mint/evm/gas.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm const ( diff --git a/manager/eris-mint/evm/log.go b/manager/eris-mint/evm/log.go index 82880ae975da279da6f2cc43c4f0b547079ef790..8b5565197bf62c487aed2852e7c65998cc5a0019 100644 --- a/manager/eris-mint/evm/log.go +++ b/manager/eris-mint/evm/log.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( diff --git a/manager/eris-mint/evm/test/log_event_test.go b/manager/eris-mint/evm/log_event_test.go similarity index 77% rename from manager/eris-mint/evm/test/log_event_test.go rename to manager/eris-mint/evm/log_event_test.go index 5f1eb2f463acfc0842878724c557d4f73d99ea6e..bdb55fb9e39c3a32453b0f5ad989a428c22aa817 100644 --- a/manager/eris-mint/evm/test/log_event_test.go +++ b/manager/eris-mint/evm/log_event_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( @@ -5,10 +19,9 @@ import ( "reflect" "testing" - . "github.com/eris-ltd/eris-db/manager/eris-mint/evm" . "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" "github.com/eris-ltd/eris-db/txs" - . "github.com/tendermint/go-common" + . "github.com/eris-ltd/eris-db/word256" "github.com/tendermint/go-events" ) diff --git a/manager/eris-mint/evm/native.go b/manager/eris-mint/evm/native.go index 860f99bd252a9037168765f2d6aa207cb1df806e..a5740c6ca7a7076cecc3eb0a5f4302433d1a9672 100644 --- a/manager/eris-mint/evm/native.go +++ b/manager/eris-mint/evm/native.go @@ -1,11 +1,25 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( "crypto/sha256" - "golang.org/x/crypto/ripemd160" + . "github.com/eris-ltd/eris-db/word256" - . "github.com/tendermint/go-common" + "golang.org/x/crypto/ripemd160" ) var registeredNativeContracts = make(map[Word256]NativeContract) @@ -40,6 +54,10 @@ func registerNativeContracts() { type NativeContract func(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error) +const FuncIDLength = 4 + +type FuncID [FuncIDLength]byte + /* Removed due to C dependency func ecrecoverFunc(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error) { // Deduct gas diff --git a/manager/eris-mint/evm/opcodes/opcodes.go b/manager/eris-mint/evm/opcodes/opcodes.go index b4205f2fe9633a80643740da942fbc51b1ff5382..ce064f213d7e94171c23206c6c821f78be1d45f4 100644 --- a/manager/eris-mint/evm/opcodes/opcodes.go +++ b/manager/eris-mint/evm/opcodes/opcodes.go @@ -1,8 +1,23 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 opcodes import ( "fmt" + "github.com/eris-ltd/eris-db/word256" "gopkg.in/fatih/set.v0" ) @@ -378,6 +393,8 @@ func Bytecode(bytelikes ...interface{}) []byte { if int64(bytes[i]) != b { panic(fmt.Sprintf("The int64 %v does not fit inside a byte", b)) } + case word256.Word256: + return Concat(bytes[:i], b[:], Bytecode(bytelikes[i+1:]...)) case []byte: // splice return Concat(bytes[:i], b, Bytecode(bytelikes[i+1:]...)) diff --git a/manager/eris-mint/evm/sha3/sha3.go b/manager/eris-mint/evm/sha3/sha3.go index da6b381f40da8a51c39aeffd5ca7791d3e74dd66..6f262f217d32a3455e3c5ed220ecf969e4df560c 100644 --- a/manager/eris-mint/evm/sha3/sha3.go +++ b/manager/eris-mint/evm/sha3/sha3.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +package sha3 + // Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012. // This file provides a SHA3 implementation which implements the standard hash.Hash interface. // Writing input data, including padding, and reading output data are computed in this file. @@ -9,7 +11,6 @@ // This is a consequence of the hash interface in which a buffer of bytes is passed in. // The internals of the Keccak-f function are computed in keccakf.go. // For the detailed specification, refer to the Keccak web site (http://keccak.noekeon.org/). -package sha3 import ( "encoding/binary" diff --git a/manager/eris-mint/evm/snative.go b/manager/eris-mint/evm/snative.go index b0a7385e3f96b005f6cf008dd36b22cb5f836449..b15d51de5961ee5f6d5f5246b54ab7593ba5278a 100644 --- a/manager/eris-mint/evm/snative.go +++ b/manager/eris-mint/evm/snative.go @@ -1,98 +1,327 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( - "encoding/hex" "fmt" + "github.com/eris-ltd/eris-db/common/sanity" + "github.com/eris-ltd/eris-db/manager/eris-mint/evm/sha3" ptypes "github.com/eris-ltd/eris-db/permission/types" - . "github.com/tendermint/go-common" + . "github.com/eris-ltd/eris-db/word256" + + "strings" + + "github.com/eris-ltd/eris-db/manager/eris-mint/evm/abi" ) -//------------------------------------------------------------------------------------------------ -// Registered SNative contracts +// +// SNative (from 'secure natives') are native (go) contracts that are dispatched +// based on account permissions and can access and modify an account's permissions +// -var PermissionsContract = "permissions_contract" +// Metadata for SNative contract. Acts as a call target from the EVM. Can be +// used to generate bindings in a smart contract languages. +type SNativeContractDescription struct { + // Comment describing purpose of SNative contract and reason for assembling + // the particular functions + Comment string + // Name of the SNative contract + Name string + functionsByID map[FuncID]*SNativeFunctionDescription + functions []*SNativeFunctionDescription +} -func registerSNativeContracts() { - registeredNativeContracts[LeftPadWord256([]byte(PermissionsContract))] = permissionsContract - - /* - // we could expose these but we moved permission and args checks into the permissionsContract - // so calling them would be unsafe ... - registeredNativeContracts[LeftPadWord256([]byte("has_base"))] = has_base - registeredNativeContracts[LeftPadWord256([]byte("set_base"))] = set_base - registeredNativeContracts[LeftPadWord256([]byte("unset_base"))] = unset_base - registeredNativeContracts[LeftPadWord256([]byte("set_global"))] = set_global - registeredNativeContracts[LeftPadWord256([]byte("has_role"))] = has_role - registeredNativeContracts[LeftPadWord256([]byte("add_role"))] = add_role - registeredNativeContracts[LeftPadWord256([]byte("rm_role"))] = rm_role - */ -} - -//----------------------------------------------------------------------------- -// snative are native contracts that can access and modify an account's permissions - -type SNativeFuncDescription struct { - Name string - NArgs int +// Metadata for SNative functions. Act as call targets for the EVM when +// collected into an SNativeContractDescription. Can be used to generate +// bindings in a smart contract languages. +type SNativeFunctionDescription struct { + // Comment describing function's purpose, parameters, and return value + Comment string + // Function name (used to form signature) + Name string + // Function arguments (used to form signature) + Args []abi.Arg + // Function return value + Return abi.Return + // Permissions required to call function PermFlag ptypes.PermFlag - F NativeContract -} - -/* The solidity interface used to generate the abi function ids below -contract Permissions { - function has_base(address addr, int permFlag) constant returns (bool value) {} - function set_base(address addr, int permFlag, bool value) constant returns (bool val) {} - function unset_base(address addr, int permFlag) constant returns (int pf) {} - function set_global(address addr, int permFlag, bool value) constant returns (int pf) {} - function has_role(address addr, string role) constant returns (bool val) {} - function add_role(address addr, string role) constant returns (bool added) {} - function rm_role(address addr, string role) constant returns (bool removed) {} -} -*/ - -// function identifiers from the solidity abi -var PermsMap = map[string]SNativeFuncDescription{ - "e8145855": SNativeFuncDescription{"has_role", 2, ptypes.HasRole, has_role}, - "180d26f2": SNativeFuncDescription{"unset_base", 2, ptypes.UnsetBase, unset_base}, - "3a3fcc59": SNativeFuncDescription{"set_global", 2, ptypes.SetGlobal, set_global}, - "3fbf7da5": SNativeFuncDescription{"add_role", 2, ptypes.AddRole, add_role}, - "9ea53314": SNativeFuncDescription{"set_base", 3, ptypes.SetBase, set_base}, - "bb37737a": SNativeFuncDescription{"has_base", 2, ptypes.HasBase, has_base}, - "28fd0194": SNativeFuncDescription{"rm_role", 2, ptypes.RmRole, rm_role}, -} - -func permissionsContract(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { - if len(args) < 4 { - return nil, fmt.Errorf("permissionsContract expects at least a 4-byte function identifier") - } - - // map solidity abi function id to snative - funcIDbytes := args[:4] - args = args[4:] - funcID := hex.EncodeToString(funcIDbytes) - d, ok := PermsMap[funcID] - if !ok { - return nil, fmt.Errorf("unknown permissionsContract funcID %s", funcID) + // Native function to which calls will be dispatched when a containing + // contract is called with a FuncID matching this NativeContract + F NativeContract +} + +func registerSNativeContracts() { + for _, contract := range SNativeContracts() { + registeredNativeContracts[contract.Address()] = contract.Dispatch + } +} + +// Returns a map of all SNative contracts defined indexed by name +func SNativeContracts() map[string]*SNativeContractDescription { + permFlagType := abi.Uint64 + roleType := abi.Bytes32 + contracts := []*SNativeContractDescription{ + NewSNativeContract(` + * Interface for managing Secure Native authorizations. + * @dev This interface describes the functions exposed by the SNative permissions layer in the Monax blockchain (ErisDB). + `, + "Permissions", + &SNativeFunctionDescription{` + * @notice Adds a role to an account + * @param _account account address + * @param _role role name + * @return result whether role was added + `, + "addRole", + []abi.Arg{ + arg("_account", abi.Address), + arg("_role", roleType), + }, + ret("result", abi.Bool), + ptypes.AddRole, + addRole}, + + &SNativeFunctionDescription{` + * @notice Removes a role from an account + * @param _account account address + * @param _role role name + * @return result whether role was removed + `, + "removeRole", + []abi.Arg{ + arg("_account", abi.Address), + arg("_role", roleType), + }, + ret("result", abi.Bool), + ptypes.RmRole, + removeRole}, + + &SNativeFunctionDescription{` + * @notice Indicates whether an account has a role + * @param _account account address + * @param _role role name + * @return result whether account has role + `, + "hasRole", + []abi.Arg{ + arg("_account", abi.Address), + arg("_role", roleType), + }, + ret("result", abi.Bool), + ptypes.HasRole, + hasRole}, + + &SNativeFunctionDescription{` + * @notice Sets the permission flags for an account. Makes them explicitly set (on or off). + * @param _account account address + * @param _permission the base permissions flags to set for the account + * @param _set whether to set or unset the permissions flags at the account level + * @return result the effective permissions flags on the account after the call + `, + "setBase", + []abi.Arg{ + arg("_account", abi.Address), + arg("_permission", permFlagType), + arg("_set", abi.Bool), + }, + ret("result", permFlagType), + ptypes.SetBase, + setBase}, + + &SNativeFunctionDescription{` + * @notice Unsets the permissions flags for an account. Causes permissions being unset to fall through to global permissions. + * @param _account account address + * @param _permission the permissions flags to unset for the account + * @return result the effective permissions flags on the account after the call + `, + "unsetBase", + []abi.Arg{ + arg("_account", abi.Address), + arg("_permission", permFlagType)}, + ret("result", permFlagType), + ptypes.UnsetBase, + unsetBase}, + + &SNativeFunctionDescription{` + * @notice Indicates whether an account has a subset of permissions set + * @param _account account address + * @param _permission the permissions flags (mask) to check whether enabled against base permissions for the account + * @return result whether account has the passed permissions flags set + `, + "hasBase", + []abi.Arg{ + arg("_account", abi.Address), + arg("_permission", permFlagType)}, + ret("result", permFlagType), + ptypes.HasBase, + hasBase}, + + &SNativeFunctionDescription{` + * @notice Sets the global (default) permissions flags for the entire chain + * @param _permission the permissions flags to set + * @param _set whether to set (or unset) the permissions flags + * @return result the global permissions flags after the call + `, + "setGlobal", + []abi.Arg{ + arg("_permission", permFlagType), + arg("_set", abi.Bool)}, + ret("result", permFlagType), + ptypes.SetGlobal, + setGlobal}, + ), + } + + contractMap := make(map[string]*SNativeContractDescription, len(contracts)) + for _, contract := range contracts { + contractMap[contract.Name] = contract + } + return contractMap +} + +// Create a new SNative contract description object by passing a comment, name +// and a list of member functions descriptions +func NewSNativeContract(comment, name string, + functions ...*SNativeFunctionDescription) *SNativeContractDescription { + + functionsByID := make(map[FuncID]*SNativeFunctionDescription, len(functions)) + for _, f := range functions { + fid := f.ID() + otherF, ok := functionsByID[fid] + if ok { + panic(fmt.Errorf("Function with ID %x already defined: %s", fid, + otherF)) + } + functionsByID[fid] = f + } + return &SNativeContractDescription{ + Comment: comment, + Name: name, + functionsByID: functionsByID, + functions: functions, + } +} + +// This function is designed to be called from the EVM once a SNative contract +// has been selected. It is also placed in a registry by registerSNativeContracts +// So it can be looked up by SNative address +func (contract *SNativeContractDescription) Dispatch(appState AppState, + caller *Account, args []byte, gas *int64) (output []byte, err error) { + if len(args) < FuncIDLength { + return nil, fmt.Errorf("SNatives dispatch requires a 4-byte function "+ + "identifier but arguments are only %s bytes long", len(args)) + } + + function, err := contract.FunctionByID(firstFourBytes(args)) + if err != nil { + return nil, err } + remainingArgs := args[FuncIDLength:] + // check if we have permission to call this function - if !HasPermission(appState, caller, d.PermFlag) { - return nil, ErrInvalidPermission{caller.Address, d.Name} + if !HasPermission(appState, caller, function.PermFlag) { + return nil, ErrInvalidPermission{caller.Address, function.Name} } // ensure there are enough arguments - if len(args) != d.NArgs*32 { - return nil, fmt.Errorf("%s() takes %d arguments", d.Name) + if len(remainingArgs) != function.NArgs()*Word256Length { + return nil, fmt.Errorf("%s() takes %d arguments", function.Name, + function.NArgs()) } // call the function - return d.F(appState, caller, args, gas) + return function.F(appState, caller, remainingArgs, gas) } -// TODO: catch errors, log em, return 0s to the vm (should some errors cause exceptions though?) +// We define the address of an SNative contact as the simplest possible hash of +// its canonical name +func (contract *SNativeContractDescription) Address() Word256 { + return LeftPadWord256([]byte(contract.Name)) +} -func has_base(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { +// Get function by calling identifier FuncID +func (contract *SNativeContractDescription) FunctionByID(id FuncID) (*SNativeFunctionDescription, error) { + f, ok := contract.functionsByID[id] + if !ok { + return nil, + fmt.Errorf("Unknown SNative function with ID %x", id) + } + return f, nil +} + +// Get function by name +func (contract *SNativeContractDescription) FunctionByName(name string) (*SNativeFunctionDescription, error) { + for _, f := range contract.functions { + if f.Name == name { + return f, nil + } + } + return nil, fmt.Errorf("Unknown SNative function with name %s", name) +} + +// Get functions in order of declaration +func (contract *SNativeContractDescription) Functions() []*SNativeFunctionDescription { + functions := make([]*SNativeFunctionDescription, len(contract.functions)) + copy(functions, contract.functions) + return functions +} + +// +// SNative functions +// + +// Get function signature +func (function *SNativeFunctionDescription) Signature() string { + argTypes := make([]string, len(function.Args)) + for i, arg := range function.Args { + argTypes[i] = string(arg.Type) + } + return fmt.Sprintf("%s(%s)", function.Name, + strings.Join(argTypes, ",")) +} + +// Get function calling identifier FuncID +func (function *SNativeFunctionDescription) ID() FuncID { + return firstFourBytes(sha3.Sha3([]byte(function.Signature()))) +} + +// Get number of function arguments +func (function *SNativeFunctionDescription) NArgs() int { + return len(function.Args) +} + +func arg(name string, abiType abi.Type) abi.Arg { + return abi.Arg{ + Name: name, + Type: abiType, + } +} + +func ret(name string, abiType abi.Type) abi.Return { + return abi.Return{ + Name: name, + Type: abiType, + } +} + +// Permission function defintions + +// TODO: catch errors, log em, return 0s to the vm (should some errors cause exceptions though?) +func hasBase(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { addr, permNum := returnTwoArgs(args) vmAcc := appState.GetAccount(addr) if vmAcc == nil { @@ -107,8 +336,8 @@ func has_base(appState AppState, caller *Account, args []byte, gas *int64) (outp return LeftPadWord256([]byte{permInt}).Bytes(), nil } -func set_base(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { - addr, permNum, perm := returnThreeArgs(args) +func setBase(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { + addr, permNum, permVal := returnThreeArgs(args) vmAcc := appState.GetAccount(addr) if vmAcc == nil { return nil, fmt.Errorf("Unknown account %X", addr) @@ -117,16 +346,16 @@ func set_base(appState AppState, caller *Account, args []byte, gas *int64) (outp if !ValidPermN(permN) { return nil, ptypes.ErrInvalidPermission(permN) } - permV := !perm.IsZero() + permV := !permVal.IsZero() if err = vmAcc.Permissions.Base.Set(permN, permV); err != nil { return nil, err } appState.UpdateAccount(vmAcc) dbg.Printf("snative.setBasePerm(0x%X, %b, %v)\n", addr.Postfix(20), permN, permV) - return perm.Bytes(), nil + return effectivePermBytes(vmAcc.Permissions.Base, globalPerms(appState)), nil } -func unset_base(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { +func unsetBase(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { addr, permNum := returnTwoArgs(args) vmAcc := appState.GetAccount(addr) if vmAcc == nil { @@ -141,29 +370,29 @@ func unset_base(appState AppState, caller *Account, args []byte, gas *int64) (ou } appState.UpdateAccount(vmAcc) dbg.Printf("snative.unsetBasePerm(0x%X, %b)\n", addr.Postfix(20), permN) - return permNum.Bytes(), nil + return effectivePermBytes(vmAcc.Permissions.Base, globalPerms(appState)), nil } -func set_global(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { - permNum, perm := returnTwoArgs(args) +func setGlobal(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { + permNum, permVal := returnTwoArgs(args) vmAcc := appState.GetAccount(ptypes.GlobalPermissionsAddress256) if vmAcc == nil { - PanicSanity("cant find the global permissions account") + sanity.PanicSanity("cant find the global permissions account") } permN := ptypes.PermFlag(Uint64FromWord256(permNum)) if !ValidPermN(permN) { return nil, ptypes.ErrInvalidPermission(permN) } - permV := !perm.IsZero() + permV := !permVal.IsZero() if err = vmAcc.Permissions.Base.Set(permN, permV); err != nil { return nil, err } appState.UpdateAccount(vmAcc) dbg.Printf("snative.setGlobalPerm(%b, %v)\n", permN, permV) - return perm.Bytes(), nil + return permBytes(vmAcc.Permissions.Base.ResultantPerms()), nil } -func has_role(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { +func hasRole(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { addr, role := returnTwoArgs(args) vmAcc := appState.GetAccount(addr) if vmAcc == nil { @@ -175,7 +404,7 @@ func has_role(appState AppState, caller *Account, args []byte, gas *int64) (outp return LeftPadWord256([]byte{permInt}).Bytes(), nil } -func add_role(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { +func addRole(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { addr, role := returnTwoArgs(args) vmAcc := appState.GetAccount(addr) if vmAcc == nil { @@ -188,7 +417,7 @@ func add_role(appState AppState, caller *Account, args []byte, gas *int64) (outp return LeftPadWord256([]byte{permInt}).Bytes(), nil } -func rm_role(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { +func removeRole(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { addr, role := returnTwoArgs(args) vmAcc := appState.GetAccount(addr) if vmAcc == nil { @@ -221,6 +450,26 @@ func ValidPermN(n ptypes.PermFlag) bool { return true } +// Get the global BasePermissions +func globalPerms(appState AppState) ptypes.BasePermissions { + vmAcc := appState.GetAccount(ptypes.GlobalPermissionsAddress256) + if vmAcc == nil { + sanity.PanicSanity("cant find the global permissions account") + } + return vmAcc.Permissions.Base +} + +// Compute the effective permissions from an Account's BasePermissions by +// taking the bitwise or with the global BasePermissions resultant permissions +func effectivePermBytes(basePerms ptypes.BasePermissions, + globalPerms ptypes.BasePermissions) []byte { + return permBytes(basePerms.ResultantPerms() | globalPerms.ResultantPerms()) +} + +func permBytes(basePerms ptypes.PermFlag) []byte { + return Uint64ToWord256(uint64(basePerms)).Bytes() +} + // CONTRACT: length has already been checked func returnTwoArgs(args []byte) (a Word256, b Word256) { copy(a[:], args[:32]) @@ -242,3 +491,9 @@ func byteFromBool(b bool) byte { } return 0x0 } + +func firstFourBytes(byteSlice []byte) [4]byte { + var bs [4]byte + copy(bs[:], byteSlice[:4]) + return bs +} diff --git a/manager/eris-mint/evm/snative_test.go b/manager/eris-mint/evm/snative_test.go new file mode 100644 index 0000000000000000000000000000000000000000..200f37bbf5d04a6a5c242f47135aafee40a9304e --- /dev/null +++ b/manager/eris-mint/evm/snative_test.go @@ -0,0 +1,149 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm + +import ( + "encoding/hex" + "testing" + + "strings" + + . "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" + ptypes "github.com/eris-ltd/eris-db/permission/types" + . "github.com/eris-ltd/eris-db/word256" + "github.com/stretchr/testify/assert" +) + +// Compiling the Permissions solidity contract at +// (generated by with 'make snatives' function) and passing to +// https://ethereum.github.io/browser-solidity (toggle details to get list) +// yields: +// Keep this updated to drive TestPermissionsContractSignatures +const compiledSigs = ` +a73f7f8a addRole(address,bytes32) +225b6574 hasBase(address,uint64) +ac4ab3fb hasRole(address,bytes32) +6853920e removeRole(address,bytes32) +dbd4a8ea setBase(address,uint64,bool) +c4bc7b70 setGlobal(uint64,bool) +b7d4dc0d unsetBase(address,uint64) +` + +func TestPermissionsContractSignatures(t *testing.T) { + contract := SNativeContracts()["Permissions"] + + nFuncs := len(contract.functions) + + sigMap := idToSignatureMap() + + assert.Len(t, sigMap, nFuncs, + "Permissions contract defines %s functions so we need %s "+ + "signatures in compiledSigs", + nFuncs, nFuncs) + + for funcID, signature := range sigMap { + assertFunctionIDSignature(t, contract, funcID, signature) + } +} + +func TestSNativeContractDescription_Dispatch(t *testing.T) { + contract := SNativeContracts()["Permissions"] + state := newAppState() + caller := &Account{ + Address: addr(1, 1, 1), + } + grantee := &Account{ + Address: addr(2, 2, 2), + } + state.UpdateAccount(grantee) + + function, err := contract.FunctionByName("addRole") + if err != nil { + t.Fatalf("Could not get function: %s", err) + } + funcID := function.ID() + gas := int64(1000) + + // Should fail since we have no permissions + retValue, err := contract.Dispatch(state, caller, Bytecode(funcID[:], + grantee.Address, permFlagToWord256(ptypes.CreateAccount)), &gas) + assert.Error(t, err) + if err != nil { + assert.Contains(t, err.Error(), "does not have permission") + } + + // Grant all permissions and dispatch should success + caller.Permissions = allAccountPermissions() + retValue, err = contract.Dispatch(state, caller, Bytecode(funcID[:], + grantee.Address, permFlagToWord256(ptypes.CreateAccount)), &gas) + assert.NoError(t, err) + assert.Equal(t, retValue, LeftPadBytes([]byte{1}, 32)) +} + +// +// Helpers +// +func assertFunctionIDSignature(t *testing.T, contract *SNativeContractDescription, + funcIDHex string, expectedSignature string) { + function, err := contract.FunctionByID(funcIDFromHex(t, funcIDHex)) + assert.NoError(t, err, + "Error retrieving SNativeFunctionDescription with ID %s", funcIDHex) + if err == nil { + assert.Equal(t, expectedSignature, function.Signature()) + } +} + +func funcIDFromHex(t *testing.T, hexString string) FuncID { + bs, err := hex.DecodeString(hexString) + assert.NoError(t, err, "Could not decode hex string '%s'", hexString) + if len(bs) != 4 { + t.Fatalf("FuncID must be 4 bytes but '%s' is %v bytes", hexString, + len(bs)) + } + return firstFourBytes(bs) +} + +func permFlagToWord256(permFlag ptypes.PermFlag) Word256 { + return Uint64ToWord256(uint64(permFlag)) +} + +func addr(rightBytes ...uint8) Word256 { + return LeftPadWord256(rightBytes) +} + +func allAccountPermissions() ptypes.AccountPermissions { + return ptypes.AccountPermissions{ + Base: ptypes.BasePermissions{ + Perms: ptypes.AllPermFlags, + SetBit: ptypes.AllPermFlags, + }, + Roles: []string{}, + } +} + +// turns the solidity compiler function summary into a map to drive signature +// test +func idToSignatureMap() map[string]string { + sigMap := make(map[string]string) + lines := strings.Split(compiledSigs, "\n") + for _, line := range lines { + trimmed := strings.Trim(line, " \t") + if trimmed != "" { + idSig := strings.Split(trimmed, " ") + sigMap[idSig[0]] = idSig[1] + } + } + return sigMap +} diff --git a/manager/eris-mint/evm/stack.go b/manager/eris-mint/evm/stack.go index 3f3d727f1fb8e78eb63226ecd952e2f9981ff3f9..8e5df4327810c1a6d4cbf123484cdf0b47aa226f 100644 --- a/manager/eris-mint/evm/stack.go +++ b/manager/eris-mint/evm/stack.go @@ -1,9 +1,25 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( "fmt" - . "github.com/tendermint/go-common" + "github.com/eris-ltd/eris-db/common/math/integral" + "github.com/eris-ltd/eris-db/common/sanity" + . "github.com/eris-ltd/eris-db/word256" ) // Not goroutine safe @@ -51,7 +67,7 @@ func (st *Stack) Push(d Word256) { // currently only called after Sha3 func (st *Stack) PushBytes(bz []byte) { if len(bz) != 32 { - PanicSanity("Invalid bytes size: expected 32") + sanity.PanicSanity("Invalid bytes size: expected 32") } st.Push(LeftPadWord256(bz)) } @@ -115,7 +131,7 @@ func (st *Stack) Peek() Word256 { func (st *Stack) Print(n int) { fmt.Println("### stack ###") if st.ptr > 0 { - nn := MinInt(n, st.ptr) + nn := integral.MinInt(n, st.ptr) for j, i := 0, st.ptr-1; i > st.ptr-1-nn; i-- { fmt.Printf("%-3d %X\n", j, st.data[i]) j += 1 diff --git a/manager/eris-mint/evm/types.go b/manager/eris-mint/evm/types.go index a886546e31f8148f7c2c20511e80cfec69b76714..cd5d8ce04b3baa011ad58536a54e25da00cb55ff 100644 --- a/manager/eris-mint/evm/types.go +++ b/manager/eris-mint/evm/types.go @@ -1,8 +1,24 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( + "fmt" + ptypes "github.com/eris-ltd/eris-db/permission/types" - . "github.com/tendermint/go-common" + . "github.com/eris-ltd/eris-db/word256" ) const ( @@ -23,7 +39,7 @@ func (acc *Account) String() string { if acc == nil { return "nil-VMAccount" } - return Fmt("VMAccount{%X B:%v C:%X N:%v}", + return fmt.Sprintf("VMAccount{%X B:%v C:%X N:%v}", acc.Address, acc.Balance, acc.Code, acc.Nonce) } diff --git a/manager/eris-mint/evm/vm.go b/manager/eris-mint/evm/vm.go index b44bddfeceae9b6849f51926963abf565c8599ce..ea883a63224b0e2dad3a788d2b752db842a7fdab 100644 --- a/manager/eris-mint/evm/vm.go +++ b/manager/eris-mint/evm/vm.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( @@ -6,11 +20,14 @@ import ( "fmt" "math/big" + "github.com/eris-ltd/eris-db/common/math/integral" + "github.com/eris-ltd/eris-db/common/sanity" . "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" "github.com/eris-ltd/eris-db/manager/eris-mint/evm/sha3" ptypes "github.com/eris-ltd/eris-db/permission/types" "github.com/eris-ltd/eris-db/txs" - . "github.com/tendermint/go-common" + . "github.com/eris-ltd/eris-db/word256" + "github.com/tendermint/go-events" ) @@ -94,7 +111,7 @@ func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool { v, err := acc.Permissions.Base.Get(perm) if _, ok := err.(ptypes.ErrValueNotSet); ok { if appState == nil { - log.Warn(Fmt("\n\n***** Unknown permission %b! ********\n\n", perm)) + log.Warn(fmt.Sprintf("\n\n***** Unknown permission %b! ********\n\n", perm)) return false } return HasPermission(nil, appState.GetAccount(ptypes.GlobalPermissionsAddress256), perm) @@ -141,7 +158,7 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value int64, gas err := transfer(callee, caller, value) if err != nil { // data has been corrupted in ram - PanicCrisis("Could not return value to caller") + sanity.PanicCrisis("Could not return value to caller") } } } @@ -940,7 +957,7 @@ func copyslice(src []byte) (dest []byte) { } func rightMostBytes(data []byte, n int) []byte { - size := MinInt(len(data), n) + size := integral.MinInt(len(data), n) offset := len(data) - size return data[offset:] } diff --git a/manager/eris-mint/evm/test/vm_test.go b/manager/eris-mint/evm/vm_test.go similarity index 94% rename from manager/eris-mint/evm/test/vm_test.go rename to manager/eris-mint/evm/vm_test.go index 53895c0da1b590c7754c290ed5922b086a437010..fe85590b46299b80ca8831545e02e815c926ff7b 100644 --- a/manager/eris-mint/evm/test/vm_test.go +++ b/manager/eris-mint/evm/vm_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 vm import ( @@ -10,12 +24,11 @@ import ( "errors" - . "github.com/eris-ltd/eris-db/manager/eris-mint/evm" . "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" ptypes "github.com/eris-ltd/eris-db/permission/types" "github.com/eris-ltd/eris-db/txs" + . "github.com/eris-ltd/eris-db/word256" "github.com/stretchr/testify/assert" - . "github.com/tendermint/go-common" "github.com/tendermint/go-events" ) diff --git a/manager/eris-mint/namereg.go b/manager/eris-mint/namereg.go index 25d95ffad3f97d19b654e8917c2e45a47900087d..cfc589eba271a126e46e1f4b8faafc57153ed1c7 100644 --- a/manager/eris-mint/namereg.go +++ b/manager/eris-mint/namereg.go @@ -1,21 +1,17 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// NameReg is part of the pipe for ErisMint and provides the implementation -// for the pipe to call into the ErisMint application package erismint import ( @@ -30,7 +26,9 @@ import ( event "github.com/eris-ltd/eris-db/event" ) -// The net struct. +// NameReg is part of the pipe for ErisMint and provides the implementation +// for the pipe to call into the ErisMint application + type namereg struct { erisMint *ErisMint filterFactory *event.FilterFactory diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go index 014de66207a1c2b0f27de336016d15291f9c8de6..a6e6dbe6a98c0ee359af0ff0cad315a37f4400c6 100644 --- a/manager/eris-mint/pipe.go +++ b/manager/eris-mint/pipe.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 erismint @@ -20,7 +18,6 @@ import ( "bytes" "fmt" - tm_common "github.com/tendermint/go-common" crypto "github.com/tendermint/go-crypto" db "github.com/tendermint/go-db" go_events "github.com/tendermint/go-events" @@ -44,6 +41,7 @@ import ( manager_types "github.com/eris-ltd/eris-db/manager/types" rpc_tm_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/word256" ) type erisMintPipe struct { @@ -380,7 +378,7 @@ func (pipe *erisMintPipe) GetStorage(address, key []byte) (*rpc_tm_types.ResultG storageTree := state.LoadStorage(storageRoot) _, value, exists := storageTree.Get( - tm_common.LeftPadWord256(key).Bytes()) + word256.LeftPadWord256(key).Bytes()) if !exists { // value == nil { return &rpc_tm_types.ResultGetStorage{key, nil}, nil @@ -422,12 +420,12 @@ func (pipe *erisMintPipe) Call(fromAddress, toAddress, data []byte) (*rpc_tm_typ fromAddress = []byte{} } callee := toVMAccount(outAcc) - caller := &vm.Account{Address: tm_common.LeftPadWord256(fromAddress)} + caller := &vm.Account{Address: word256.LeftPadWord256(fromAddress)} txCache := state.NewTxCache(cache) gasLimit := st.GetGasLimit() params := vm.Params{ BlockHeight: int64(st.LastBlockHeight), - BlockHash: tm_common.LeftPadWord256(st.LastBlockHash), + BlockHash: word256.LeftPadWord256(st.LastBlockHash), BlockTime: st.LastBlockTime.Unix(), GasLimit: gasLimit, } @@ -448,13 +446,13 @@ func (pipe *erisMintPipe) CallCode(fromAddress, code, data []byte) (*rpc_tm_type error) { st := pipe.erisMint.GetState() cache := pipe.erisMint.GetCheckCache() - callee := &vm.Account{Address: tm_common.LeftPadWord256(fromAddress)} - caller := &vm.Account{Address: tm_common.LeftPadWord256(fromAddress)} + callee := &vm.Account{Address: word256.LeftPadWord256(fromAddress)} + caller := &vm.Account{Address: word256.LeftPadWord256(fromAddress)} txCache := state.NewTxCache(cache) gasLimit := st.GetGasLimit() params := vm.Params{ BlockHeight: int64(st.LastBlockHeight), - BlockHash: tm_common.LeftPadWord256(st.LastBlockHash), + BlockHash: word256.LeftPadWord256(st.LastBlockHash), BlockTime: st.LastBlockTime.Unix(), GasLimit: gasLimit, } diff --git a/manager/eris-mint/state/block_cache.go b/manager/eris-mint/state/block_cache.go index 31210114e07acf57ab95aab0b1ec7b996c193445..e162ce5c3b185388484e91dca2b7ae7e7916b675 100644 --- a/manager/eris-mint/state/block_cache.go +++ b/manager/eris-mint/state/block_cache.go @@ -1,15 +1,31 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( "bytes" + "fmt" "sort" - . "github.com/tendermint/go-common" - dbm "github.com/tendermint/go-db" - "github.com/tendermint/go-merkle" - acm "github.com/eris-ltd/eris-db/account" + "github.com/eris-ltd/eris-db/common/sanity" core_types "github.com/eris-ltd/eris-db/core/types" + . "github.com/eris-ltd/eris-db/word256" + + dbm "github.com/tendermint/go-db" + "github.com/tendermint/go-merkle" ) func makeStorage(db dbm.DB, root []byte) merkle.Tree { @@ -61,7 +77,7 @@ func (cache *BlockCache) UpdateAccount(acc *acm.Account) { addr := acc.Address _, storage, removed, _ := cache.accounts[string(addr)].unpack() if removed { - PanicSanity("UpdateAccount on a removed account") + sanity.PanicSanity("UpdateAccount on a removed account") } cache.accounts[string(addr)] = accountInfo{acc, storage, false, true} } @@ -69,7 +85,7 @@ func (cache *BlockCache) UpdateAccount(acc *acm.Account) { func (cache *BlockCache) RemoveAccount(addr []byte) { _, _, removed, _ := cache.accounts[string(addr)].unpack() if removed { - PanicSanity("RemoveAccount on a removed account") + sanity.PanicSanity("RemoveAccount on a removed account") } cache.accounts[string(addr)] = accountInfo{nil, nil, true, false} } @@ -88,7 +104,7 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) { // Get or load storage acc, storage, removed, dirty := cache.accounts[string(addr.Postfix(20))].unpack() if removed { - PanicSanity("GetStorage() on removed account") + sanity.PanicSanity("GetStorage() on removed account") } if acc != nil && storage == nil { storage = makeStorage(cache.db, acc.StorageRoot) @@ -111,7 +127,7 @@ func (cache *BlockCache) GetStorage(addr Word256, key Word256) (value Word256) { func (cache *BlockCache) SetStorage(addr Word256, key Word256, value Word256) { _, _, removed, _ := cache.accounts[string(addr.Postfix(20))].unpack() if removed { - PanicSanity("SetStorage() on a removed account") + sanity.PanicSanity("SetStorage() on a removed account") } cache.storages[Tuple256{addr, key}] = storageInfo{value, true} } @@ -141,7 +157,7 @@ func (cache *BlockCache) UpdateNameRegEntry(entry *core_types.NameRegEntry) { func (cache *BlockCache) RemoveNameRegEntry(name string) { _, removed, _ := cache.names[name].unpack() if removed { - PanicSanity("RemoveNameRegEntry on a removed entry") + sanity.PanicSanity("RemoveNameRegEntry on a removed entry") } cache.names[name] = nameInfo{nil, true, false} } @@ -208,7 +224,7 @@ func (cache *BlockCache) Sync() { if removed { removed := cache.backend.RemoveAccount([]byte(addrStr)) if !removed { - PanicCrisis(Fmt("Could not remove account to be removed: %X", acc.Address)) + sanity.PanicCrisis(fmt.Sprintf("Could not remove account to be removed: %X", acc.Address)) } } else { if acc == nil { @@ -241,7 +257,7 @@ func (cache *BlockCache) Sync() { if removed { removed := cache.backend.RemoveNameRegEntry(nameStr) if !removed { - PanicCrisis(Fmt("Could not remove namereg entry to be removed: %s", nameStr)) + sanity.PanicCrisis(fmt.Sprintf("Could not remove namereg entry to be removed: %s", nameStr)) } } else { if entry == nil { diff --git a/manager/eris-mint/state/common.go b/manager/eris-mint/state/common.go index 78315627205b958179113970622090efb85b3c26..4f096d804e6808def4a1e14e97ae8f87b39fb3e3 100644 --- a/manager/eris-mint/state/common.go +++ b/manager/eris-mint/state/common.go @@ -1,9 +1,23 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( acm "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" - . "github.com/tendermint/go-common" + . "github.com/eris-ltd/eris-db/word256" ) type AccountGetter interface { diff --git a/manager/eris-mint/state/execution.go b/manager/eris-mint/state/execution.go index 9d9fd85bd3f85fc9d0cd2c50402b86a3376d98cf..80b5474f5868cd0493bb8f639730dfb3df6d11c5 100644 --- a/manager/eris-mint/state/execution.go +++ b/manager/eris-mint/state/execution.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( @@ -5,15 +19,15 @@ import ( "errors" "fmt" - . "github.com/tendermint/go-common" - "github.com/tendermint/go-events" - acm "github.com/eris-ltd/eris-db/account" + "github.com/eris-ltd/eris-db/common/sanity" + core_types "github.com/eris-ltd/eris-db/core/types" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" ptypes "github.com/eris-ltd/eris-db/permission/types" // for GlobalPermissionAddress ... - - core_types "github.com/eris-ltd/eris-db/core/types" "github.com/eris-ltd/eris-db/txs" + . "github.com/eris-ltd/eris-db/word256" + + "github.com/tendermint/go-events" ) // ExecBlock stuff is now taken care of by the consensus engine. @@ -228,7 +242,7 @@ func validateInputs(accounts map[string]*acm.Account, signBytes []byte, ins []*t for _, in := range ins { acc := accounts[string(in.Address)] if acc == nil { - PanicSanity("validateInputs() expects account in accounts") + sanity.PanicSanity("validateInputs() expects account in accounts") } err = validateInput(acc, signBytes, in) if err != nil { @@ -279,10 +293,10 @@ func adjustByInputs(accounts map[string]*acm.Account, ins []*txs.TxInput) { for _, in := range ins { acc := accounts[string(in.Address)] if acc == nil { - PanicSanity("adjustByInputs() expects account in accounts") + sanity.PanicSanity("adjustByInputs() expects account in accounts") } if acc.Balance < in.Amount { - PanicSanity("adjustByInputs() expects sufficient funds") + sanity.PanicSanity("adjustByInputs() expects sufficient funds") } acc.Balance -= in.Amount @@ -294,7 +308,7 @@ func adjustByOutputs(accounts map[string]*acm.Account, outs []*txs.TxOutput) { for _, out := range outs { acc := accounts[string(out.Address)] if acc == nil { - PanicSanity("adjustByOutputs() expects account in accounts") + sanity.PanicSanity("adjustByOutputs() expects account in accounts") } acc.Balance += out.Amount } @@ -368,7 +382,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // Validate input inAcc = blockCache.GetAccount(tx.Input.Address) if inAcc == nil { - log.Info(Fmt("Can't find in account %X", tx.Input.Address)) + log.Info(fmt.Sprintf("Can't find in account %X", tx.Input.Address)) return txs.ErrTxInvalidAddress } @@ -385,24 +399,24 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // pubKey should be present in either "inAcc" or "tx.Input" if err := checkInputPubKey(inAcc, tx.Input); err != nil { - log.Info(Fmt("Can't find pubkey for %X", tx.Input.Address)) + log.Info(fmt.Sprintf("Can't find pubkey for %X", tx.Input.Address)) return err } signBytes := acm.SignBytes(_s.ChainID, tx) err := validateInput(inAcc, signBytes, tx.Input) if err != nil { - log.Info(Fmt("validateInput failed on %X: %v", tx.Input.Address, err)) + log.Info(fmt.Sprintf("validateInput failed on %X: %v", tx.Input.Address, err)) return err } if tx.Input.Amount < tx.Fee { - log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) + log.Info(fmt.Sprintf("Sender did not send enough to cover the fee %X", tx.Input.Address)) return txs.ErrTxInsufficientFunds } if !createContract { // Validate output if len(tx.Address) != 20 { - log.Info(Fmt("Destination address is not 20 bytes %X", tx.Address)) + log.Info(fmt.Sprintf("Destination address is not 20 bytes %X", tx.Address)) return txs.ErrTxInvalidAddress } // check if its a native contract @@ -416,7 +430,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable outAcc = blockCache.GetAccount(tx.Address) } - log.Info(Fmt("Out account: %v", outAcc)) + log.Info(fmt.Sprintf("Out account: %v", outAcc)) // Good! value := tx.Input.Amount - tx.Fee @@ -454,10 +468,10 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // you have to wait a block to avoid a re-ordering attack // that will take your fees if outAcc == nil { - log.Info(Fmt("%X tries to call %X but it does not exist.", + log.Info(fmt.Sprintf("%X tries to call %X but it does not exist.", inAcc.Address, tx.Address)) } else { - log.Info(Fmt("%X tries to call %X but code is blank.", + log.Info(fmt.Sprintf("%X tries to call %X but code is blank.", inAcc.Address, tx.Address)) } err = txs.ErrTxInvalidAddress @@ -468,14 +482,14 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable if createContract { // We already checked for permission callee = txCache.CreateAccount(caller) - log.Info(Fmt("Created new contract %X", callee.Address)) + log.Info(fmt.Sprintf("Created new contract %X", callee.Address)) code = tx.Data } else { callee = toVMAccount(outAcc) - log.Info(Fmt("Calling contract %X with code %X", callee.Address, callee.Code)) + log.Info(fmt.Sprintf("Calling contract %X with code %X", callee.Address, callee.Code)) code = callee.Code } - log.Info(Fmt("Code for this contract: %X", code)) + log.Info(fmt.Sprintf("Code for this contract: %X", code)) // Run VM call and sync txCache to blockCache. { // Capture scope for goto. @@ -488,7 +502,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable ret, err = vmach.Call(caller, callee, code, tx.Data, value, &gas) if err != nil { // Failure. Charge the gas fee. The 'value' was otherwise not transferred. - log.Info(Fmt("Error on execution: %v", err)) + log.Info(fmt.Sprintf("Error on execution: %v", err)) goto CALL_COMPLETE } @@ -534,7 +548,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // Validate input inAcc = blockCache.GetAccount(tx.Input.Address) if inAcc == nil { - log.Info(Fmt("Can't find in account %X", tx.Input.Address)) + log.Info(fmt.Sprintf("Can't find in account %X", tx.Input.Address)) return txs.ErrTxInvalidAddress } // check permission @@ -543,18 +557,18 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable } // pubKey should be present in either "inAcc" or "tx.Input" if err := checkInputPubKey(inAcc, tx.Input); err != nil { - log.Info(Fmt("Can't find pubkey for %X", tx.Input.Address)) + log.Info(fmt.Sprintf("Can't find pubkey for %X", tx.Input.Address)) return err } signBytes := acm.SignBytes(_s.ChainID, tx) err := validateInput(inAcc, signBytes, tx.Input) if err != nil { - log.Info(Fmt("validateInput failed on %X: %v", tx.Input.Address, err)) + log.Info(fmt.Sprintf("validateInput failed on %X: %v", tx.Input.Address, err)) return err } // fee is in addition to the amount which is used to determine the TTL if tx.Input.Amount < tx.Fee { - log.Info(Fmt("Sender did not send enough to cover the fee %X", tx.Input.Address)) + log.Info(fmt.Sprintf("Sender did not send enough to cover the fee %X", tx.Input.Address)) return txs.ErrTxInsufficientFunds } @@ -582,7 +596,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable if entry.Expires > lastBlockHeight { // ensure we are owner if bytes.Compare(entry.Owner, tx.Input.Address) != 0 { - log.Info(Fmt("Sender %X is trying to update a name (%s) for which he is not owner", tx.Input.Address, tx.Name)) + log.Info(fmt.Sprintf("Sender %X is trying to update a name (%s) for which he is not owner", tx.Input.Address, tx.Name)) return txs.ErrTxPermissionDenied } } else { @@ -600,7 +614,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // and changing the data if expired { if expiresIn < txs.MinNameRegistrationPeriod { - return errors.New(Fmt("Names must be registered for at least %d blocks", txs.MinNameRegistrationPeriod)) + return errors.New(fmt.Sprintf("Names must be registered for at least %d blocks", txs.MinNameRegistrationPeriod)) } entry.Expires = lastBlockHeight + expiresIn entry.Owner = tx.Input.Address @@ -612,7 +626,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable credit := oldCredit + value expiresIn = int(credit / costPerBlock) if expiresIn < txs.MinNameRegistrationPeriod { - return errors.New(Fmt("Names must be registered for at least %d blocks", txs.MinNameRegistrationPeriod)) + return errors.New(fmt.Sprintf("Names must be registered for at least %d blocks", txs.MinNameRegistrationPeriod)) } entry.Expires = lastBlockHeight + expiresIn log.Info("Updated namereg entry", "name", entry.Name, "expiresIn", expiresIn, "oldCredit", oldCredit, "value", value, "credit", credit) @@ -622,7 +636,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable } } else { if expiresIn < txs.MinNameRegistrationPeriod { - return errors.New(Fmt("Names must be registered for at least %d blocks", txs.MinNameRegistrationPeriod)) + return errors.New(fmt.Sprintf("Names must be registered for at least %d blocks", txs.MinNameRegistrationPeriod)) } // entry does not exist, so create it entry = &core_types.NameRegEntry{ @@ -834,7 +848,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // Validate input inAcc = blockCache.GetAccount(tx.Input.Address) if inAcc == nil { - log.Debug(Fmt("Can't find in account %X", tx.Input.Address)) + log.Debug(fmt.Sprintf("Can't find in account %X", tx.Input.Address)) return txs.ErrTxInvalidAddress } @@ -846,13 +860,13 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // pubKey should be present in either "inAcc" or "tx.Input" if err := checkInputPubKey(inAcc, tx.Input); err != nil { - log.Debug(Fmt("Can't find pubkey for %X", tx.Input.Address)) + log.Debug(fmt.Sprintf("Can't find pubkey for %X", tx.Input.Address)) return err } signBytes := acm.SignBytes(_s.ChainID, tx) err := validateInput(inAcc, signBytes, tx.Input) if err != nil { - log.Debug(Fmt("validateInput failed on %X: %v", tx.Input.Address, err)) + log.Debug(fmt.Sprintf("validateInput failed on %X: %v", tx.Input.Address, err)) return err } @@ -877,7 +891,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable err = permAcc.Permissions.Base.Unset(args.Permission) case *ptypes.SetGlobalArgs: if permAcc = blockCache.GetAccount(ptypes.GlobalPermissionsAddress); permAcc == nil { - PanicSanity("can't find global permissions account") + sanity.PanicSanity("can't find global permissions account") } err = permAcc.Permissions.Base.Set(args.Permission, args.Value) case *ptypes.HasRoleArgs: @@ -897,7 +911,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable return fmt.Errorf("Role (%s) does not exist for account %X", args.Role, args.Address) } default: - PanicSanity(Fmt("invalid permission function: %s", ptypes.PermFlagToString(permFlag))) + sanity.PanicSanity(fmt.Sprintf("invalid permission function: %s", ptypes.PermFlagToString(permFlag))) } // TODO: maybe we want to take funds on error and allow txs in that don't do anythingi? @@ -922,7 +936,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable default: // binary decoding should not let this happen - PanicSanity("Unknown Tx type") + sanity.PanicSanity("Unknown Tx type") return nil } } @@ -932,7 +946,7 @@ func ExecTx(blockCache *BlockCache, tx txs.Tx, runCall bool, evc events.Fireable // Get permission on an account or fall back to global value func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) bool { if perm > ptypes.AllPermFlags { - PanicSanity("Checking an unknown permission in state should never happen") + sanity.PanicSanity("Checking an unknown permission in state should never happen") } if acc == nil { @@ -945,14 +959,14 @@ func HasPermission(state AccountGetter, acc *acm.Account, perm ptypes.PermFlag) v, err := acc.Permissions.Base.Get(perm) if _, ok := err.(ptypes.ErrValueNotSet); ok { if state == nil { - PanicSanity("All known global permissions should be set!") + sanity.PanicSanity("All known global permissions should be set!") } log.Info("Permission for account is not set. Querying GlobalPermissionsAddress", "perm", permString) return HasPermission(nil, state.GetAccount(ptypes.GlobalPermissionsAddress), perm) } else if v { - log.Info("Account has permission", "address", Fmt("%X", acc.Address), "perm", permString) + log.Info("Account has permission", "address", fmt.Sprintf("%X", acc.Address), "perm", permString) } else { - log.Info("Account does not have permission", "address", Fmt("%X", acc.Address), "perm", permString) + log.Info("Account does not have permission", "address", fmt.Sprintf("%X", acc.Address), "perm", permString) } return v } @@ -1011,5 +1025,5 @@ type InvalidTxError struct { } func (txErr InvalidTxError) Error() string { - return Fmt("Invalid tx: [%v] reason: [%v]", txErr.Tx, txErr.Reason) + return fmt.Sprintf("Invalid tx: [%v] reason: [%v]", txErr.Tx, txErr.Reason) } diff --git a/manager/eris-mint/state/genesis_test.go b/manager/eris-mint/state/genesis_test.go index 3bc2fdf005fc50686e698ef061a1340def5e8619..1aa25bc05bbd580eb33231004e0034d8f5e922b3 100644 --- a/manager/eris-mint/state/genesis_test.go +++ b/manager/eris-mint/state/genesis_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( @@ -9,10 +23,10 @@ import ( "time" acm "github.com/eris-ltd/eris-db/account" + "github.com/eris-ltd/eris-db/common/random" genesis "github.com/eris-ltd/eris-db/genesis" ptypes "github.com/eris-ltd/eris-db/permission/types" - . "github.com/tendermint/go-common" tdb "github.com/tendermint/go-db" "github.com/tendermint/tendermint/types" ) @@ -31,7 +45,7 @@ var g1 = fmt.Sprintf(` { "address": "%X", "amount": %d, - "name": "%s", + "name": "%s", "permissions": { "base": { "perms": %d, @@ -108,12 +122,12 @@ func RandAccount(randBalance bool, minBalance int64) (*acm.Account, *acm.PrivAcc acc := &acm.Account{ Address: privAccount.PubKey.Address(), PubKey: privAccount.PubKey, - Sequence: RandInt(), + Sequence: random.RandInt(), Balance: minBalance, Permissions: perms, } if randBalance { - acc.Balance += int64(RandUint32()) + acc.Balance += int64(random.RandUint32()) } return acc, privAccount } diff --git a/manager/eris-mint/state/log.go b/manager/eris-mint/state/log.go index 5b102b5703e0474c1ee2db377f3b95c7a8705c3c..d8e71b796dd6dc0599c7bebea5257b0a2283c1d7 100644 --- a/manager/eris-mint/state/log.go +++ b/manager/eris-mint/state/log.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( diff --git a/manager/eris-mint/state/permissions_test.go b/manager/eris-mint/state/permissions_test.go index 8632313647c5ef8a0d03a1f6716c661f8b75274c..28da492697e71cc4528475697c341205d91301ba 100644 --- a/manager/eris-mint/state/permissions_test.go +++ b/manager/eris-mint/state/permissions_test.go @@ -1,8 +1,21 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( "bytes" - "encoding/hex" "fmt" "strconv" "testing" @@ -11,15 +24,14 @@ import ( acm "github.com/eris-ltd/eris-db/account" genesis "github.com/eris-ltd/eris-db/genesis" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + . "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" ptypes "github.com/eris-ltd/eris-db/permission/types" "github.com/eris-ltd/eris-db/txs" + . "github.com/eris-ltd/eris-db/word256" - . "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes" - . "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" dbm "github.com/tendermint/go-db" "github.com/tendermint/go-events" - "github.com/tendermint/tendermint/config/tendermint_test" ) @@ -28,8 +40,9 @@ func init() { } var ( - dbBackend = "memdb" - dbDir = "" + dbBackend = "memdb" + dbDir = "" + permissionsContract = vm.SNativeContracts()["Permissions"] ) /* @@ -886,7 +899,7 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### HasBase") // HasBase - snativeAddress, pF, data := snativePermTestInputCALL("has_base", user[3], ptypes.Bond, false) + snativeAddress, pF, data := snativePermTestInputCALL("hasBase", user[3], ptypes.Bond, false) testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { // return value should be true or false as a 32 byte array... @@ -898,10 +911,10 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### SetBase") // SetBase - snativeAddress, pF, data = snativePermTestInputCALL("set_base", user[3], ptypes.Bond, false) + snativeAddress, pF, data = snativePermTestInputCALL("setBase", user[3], ptypes.Bond, false) testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { return nil }) - snativeAddress, pF, data = snativePermTestInputCALL("has_base", user[3], ptypes.Bond, false) + snativeAddress, pF, data = snativePermTestInputCALL("hasBase", user[3], ptypes.Bond, false) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { // return value should be true or false as a 32 byte array... if !IsZeros(ret) { @@ -909,9 +922,9 @@ func TestSNativeCALL(t *testing.T) { } return nil }) - snativeAddress, pF, data = snativePermTestInputCALL("set_base", user[3], ptypes.CreateContract, true) + snativeAddress, pF, data = snativePermTestInputCALL("setBase", user[3], ptypes.CreateContract, true) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { return nil }) - snativeAddress, pF, data = snativePermTestInputCALL("has_base", user[3], ptypes.CreateContract, false) + snativeAddress, pF, data = snativePermTestInputCALL("hasBase", user[3], ptypes.CreateContract, false) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { // return value should be true or false as a 32 byte array... if !IsZeros(ret[:31]) || ret[31] != byte(1) { @@ -922,10 +935,10 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### UnsetBase") // UnsetBase - snativeAddress, pF, data = snativePermTestInputCALL("unset_base", user[3], ptypes.CreateContract, false) + snativeAddress, pF, data = snativePermTestInputCALL("unsetBase", user[3], ptypes.CreateContract, false) testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { return nil }) - snativeAddress, pF, data = snativePermTestInputCALL("has_base", user[3], ptypes.CreateContract, false) + snativeAddress, pF, data = snativePermTestInputCALL("hasBase", user[3], ptypes.CreateContract, false) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { if !IsZeros(ret) { return fmt.Errorf("Expected 0. Got %X", ret) @@ -935,10 +948,10 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### SetGlobal") // SetGlobalPerm - snativeAddress, pF, data = snativePermTestInputCALL("set_global", user[3], ptypes.CreateContract, true) + snativeAddress, pF, data = snativePermTestInputCALL("setGlobal", user[3], ptypes.CreateContract, true) testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { return nil }) - snativeAddress, pF, data = snativePermTestInputCALL("has_base", user[3], ptypes.CreateContract, false) + snativeAddress, pF, data = snativePermTestInputCALL("hasBase", user[3], ptypes.CreateContract, false) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { // return value should be true or false as a 32 byte array... if !IsZeros(ret[:31]) || ret[31] != byte(1) { @@ -949,7 +962,7 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### HasRole") // HasRole - snativeAddress, pF, data = snativeRoleTestInputCALL("has_role", user[3], "bumble") + snativeAddress, pF, data = snativeRoleTestInputCALL("hasRole", user[3], "bumble") testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { if !IsZeros(ret[:31]) || ret[31] != byte(1) { @@ -960,17 +973,17 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### AddRole") // AddRole - snativeAddress, pF, data = snativeRoleTestInputCALL("has_role", user[3], "chuck") + snativeAddress, pF, data = snativeRoleTestInputCALL("hasRole", user[3], "chuck") testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { if !IsZeros(ret) { return fmt.Errorf("Expected 0. Got %X", ret) } return nil }) - snativeAddress, pF, data = snativeRoleTestInputCALL("add_role", user[3], "chuck") + snativeAddress, pF, data = snativeRoleTestInputCALL("addRole", user[3], "chuck") testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { return nil }) - snativeAddress, pF, data = snativeRoleTestInputCALL("has_role", user[3], "chuck") + snativeAddress, pF, data = snativeRoleTestInputCALL("hasRole", user[3], "chuck") testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { if !IsZeros(ret[:31]) || ret[31] != byte(1) { return fmt.Errorf("Expected 1. Got %X", ret) @@ -980,10 +993,10 @@ func TestSNativeCALL(t *testing.T) { fmt.Println("\n#### RmRole") // RmRole - snativeAddress, pF, data = snativeRoleTestInputCALL("rm_role", user[3], "chuck") + snativeAddress, pF, data = snativeRoleTestInputCALL("removeRole", user[3], "chuck") testSNativeCALLExpectFail(t, blockCache, doug, snativeAddress, data) testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { return nil }) - snativeAddress, pF, data = snativeRoleTestInputCALL("has_role", user[3], "chuck") + snativeAddress, pF, data = snativeRoleTestInputCALL("hasRole", user[3], "chuck") testSNativeCALLExpectPass(t, blockCache, doug, pF, snativeAddress, data, func(ret []byte) error { if !IsZeros(ret) { return fmt.Errorf("Expected 0. Got %X", ret) @@ -1007,14 +1020,14 @@ func TestSNativeTx(t *testing.T) { fmt.Println("\n#### SetBase") // SetBase - snativeArgs := snativePermTestInputTx("set_base", user[3], ptypes.Bond, false) + snativeArgs := snativePermTestInputTx("setBase", user[3], ptypes.Bond, false) testSNativeTxExpectFail(t, blockCache, snativeArgs) testSNativeTxExpectPass(t, blockCache, ptypes.SetBase, snativeArgs) acc := blockCache.GetAccount(user[3].Address) if v, _ := acc.Permissions.Base.Get(ptypes.Bond); v { t.Fatal("expected permission to be set false") } - snativeArgs = snativePermTestInputTx("set_base", user[3], ptypes.CreateContract, true) + snativeArgs = snativePermTestInputTx("setBase", user[3], ptypes.CreateContract, true) testSNativeTxExpectPass(t, blockCache, ptypes.SetBase, snativeArgs) acc = blockCache.GetAccount(user[3].Address) if v, _ := acc.Permissions.Base.Get(ptypes.CreateContract); !v { @@ -1023,7 +1036,7 @@ func TestSNativeTx(t *testing.T) { fmt.Println("\n#### UnsetBase") // UnsetBase - snativeArgs = snativePermTestInputTx("unset_base", user[3], ptypes.CreateContract, false) + snativeArgs = snativePermTestInputTx("unsetBase", user[3], ptypes.CreateContract, false) testSNativeTxExpectFail(t, blockCache, snativeArgs) testSNativeTxExpectPass(t, blockCache, ptypes.UnsetBase, snativeArgs) acc = blockCache.GetAccount(user[3].Address) @@ -1033,7 +1046,7 @@ func TestSNativeTx(t *testing.T) { fmt.Println("\n#### SetGlobal") // SetGlobalPerm - snativeArgs = snativePermTestInputTx("set_global", user[3], ptypes.CreateContract, true) + snativeArgs = snativePermTestInputTx("setGlobal", user[3], ptypes.CreateContract, true) testSNativeTxExpectFail(t, blockCache, snativeArgs) testSNativeTxExpectPass(t, blockCache, ptypes.SetGlobal, snativeArgs) acc = blockCache.GetAccount(ptypes.GlobalPermissionsAddress) @@ -1043,7 +1056,7 @@ func TestSNativeTx(t *testing.T) { fmt.Println("\n#### AddRole") // AddRole - snativeArgs = snativeRoleTestInputTx("add_role", user[3], "chuck") + snativeArgs = snativeRoleTestInputTx("addRole", user[3], "chuck") testSNativeTxExpectFail(t, blockCache, snativeArgs) testSNativeTxExpectPass(t, blockCache, ptypes.AddRole, snativeArgs) acc = blockCache.GetAccount(user[3].Address) @@ -1053,7 +1066,7 @@ func TestSNativeTx(t *testing.T) { fmt.Println("\n#### RmRole") // RmRole - snativeArgs = snativeRoleTestInputTx("rm_role", user[3], "chuck") + snativeArgs = snativeRoleTestInputTx("removeRole", user[3], "chuck") testSNativeTxExpectFail(t, blockCache, snativeArgs) testSNativeTxExpectPass(t, blockCache, ptypes.RmRole, snativeArgs) acc = blockCache.GetAccount(user[3].Address) @@ -1183,72 +1196,71 @@ func boolToWord256(v bool) Word256 { return LeftPadWord256([]byte{vint}) } -func permNameToFuncID(s string) []byte { - for k, v := range vm.PermsMap { - if s == v.Name { - b, _ := hex.DecodeString(k) - return b - } +func permNameToFuncID(name string) []byte { + function, err := permissionsContract.FunctionByName(name) + if err != nil { + panic("didn't find snative function signature!") } - panic("didn't find snative function signature!") + id := function.ID() + return id[:] } func snativePermTestInputCALL(name string, user *acm.PrivAccount, perm ptypes.PermFlag, val bool) (addr []byte, pF ptypes.PermFlag, data []byte) { - addr = LeftPadWord256([]byte(vm.PermissionsContract)).Postfix(20) + addr = permissionsContract.Address().Postfix(20) switch name { - case "has_base", "unset_base": + case "hasBase", "unsetBase": data = LeftPadBytes(user.Address, 32) data = append(data, Uint64ToWord256(uint64(perm)).Bytes()...) - case "set_base": + case "setBase": data = LeftPadBytes(user.Address, 32) data = append(data, Uint64ToWord256(uint64(perm)).Bytes()...) data = append(data, boolToWord256(val).Bytes()...) - case "set_global": + case "setGlobal": data = Uint64ToWord256(uint64(perm)).Bytes() data = append(data, boolToWord256(val).Bytes()...) } data = append(permNameToFuncID(name), data...) var err error if pF, err = ptypes.PermStringToFlag(name); err != nil { - panic(Fmt("failed to convert perm string (%s) to flag", name)) + panic(fmt.Sprintf("failed to convert perm string (%s) to flag", name)) } return } func snativePermTestInputTx(name string, user *acm.PrivAccount, perm ptypes.PermFlag, val bool) (snativeArgs ptypes.PermArgs) { switch name { - case "has_base": + case "hasBase": snativeArgs = &ptypes.HasBaseArgs{user.Address, perm} - case "unset_base": + case "unsetBase": snativeArgs = &ptypes.UnsetBaseArgs{user.Address, perm} - case "set_base": + case "setBase": snativeArgs = &ptypes.SetBaseArgs{user.Address, perm, val} - case "set_global": + case "setGlobal": snativeArgs = &ptypes.SetGlobalArgs{perm, val} } return } func snativeRoleTestInputCALL(name string, user *acm.PrivAccount, role string) (addr []byte, pF ptypes.PermFlag, data []byte) { - addr = LeftPadWord256([]byte(vm.PermissionsContract)).Postfix(20) + addr = permissionsContract.Address().Postfix(20) data = LeftPadBytes(user.Address, 32) data = append(data, RightPadBytes([]byte(role), 32)...) data = append(permNameToFuncID(name), data...) var err error if pF, err = ptypes.PermStringToFlag(name); err != nil { - panic(Fmt("failed to convert perm string (%s) to flag", name)) + panic(fmt.Sprintf("failed to convert perm string (%s) to flag", name)) } return } func snativeRoleTestInputTx(name string, user *acm.PrivAccount, role string) (snativeArgs ptypes.PermArgs) { switch name { - case "has_role": + case "hasRole": snativeArgs = &ptypes.HasRoleArgs{user.Address, role} - case "add_role": + case "addRole": snativeArgs = &ptypes.AddRoleArgs{user.Address, role} - case "rm_role": + case "removeRole": snativeArgs = &ptypes.RmRoleArgs{user.Address, role} } return diff --git a/manager/eris-mint/state/state.go b/manager/eris-mint/state/state.go index a9dd607fff77964105a6da01e0aedf1035b47a24..3d61775422fe5014a0e961deaf59925843f48728 100644 --- a/manager/eris-mint/state/state.go +++ b/manager/eris-mint/state/state.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( @@ -416,10 +430,12 @@ func MakeGenesisState(db dbm.DB, genDoc *genesis.GenesisDoc) *State { } if genDoc.GenesisTime.IsZero() { - // MARMOT: really? - // set time to 11/18/2016 @ 4:09am (UTC) + // NOTE: [ben] change GenesisTime to requirement on v0.17 + // GenesisTime needs to be deterministic across the chain + // and should be required in the genesis file; + // the requirement is not yet enforced when lacking set + // time to 11/18/2016 @ 4:09am (UTC) genDoc.GenesisTime = time.Unix(1479442162, 0) - // genDoc.GenesisTime = time.Now() } // Make accounts state tree diff --git a/manager/eris-mint/state/state_test.go b/manager/eris-mint/state/state_test.go index dd6e07b9b6b9e1a3301e5529b411ffafee7c6251..b9d032ed3cadeddf8548603b556f217c68424089 100644 --- a/manager/eris-mint/state/state_test.go +++ b/manager/eris-mint/state/state_test.go @@ -1,18 +1,30 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( "bytes" "encoding/hex" "testing" - //"time" - - "github.com/tendermint/go-common" - "github.com/tendermint/tendermint/config/tendermint_test" - // tmtypes "github.com/tendermint/tendermint/types" core_types "github.com/eris-ltd/eris-db/core/types" evm "github.com/eris-ltd/eris-db/manager/eris-mint/evm" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/word256" + + "github.com/tendermint/tendermint/config/tendermint_test" ) func init() { @@ -429,7 +441,7 @@ func TestCreates(t *testing.T) { state.UpdateAccount(newAcc1) state.UpdateAccount(newAcc2) - createData = append(createData, common.LeftPadBytes(acc2.Address, 32)...) + createData = append(createData, word256.LeftPadBytes(acc2.Address, 32)...) // call the pre-factory, triggering the factory to run a create tx := &txs.CallTx{ @@ -452,7 +464,7 @@ func TestCreates(t *testing.T) { acc1 = state.GetAccount(acc1.Address) storage := state.LoadStorage(acc1.StorageRoot) - _, firstCreatedAddress, _ := storage.Get(common.LeftPadBytes([]byte{0}, 32)) + _, firstCreatedAddress, _ := storage.Get(word256.LeftPadBytes([]byte{0}, 32)) acc0 = state.GetAccount(acc0.Address) // call the pre-factory, triggering the factory to run a create @@ -476,7 +488,7 @@ func TestCreates(t *testing.T) { acc1 = state.GetAccount(acc1.Address) storage = state.LoadStorage(acc1.StorageRoot) - _, secondCreatedAddress, _ := storage.Get(common.LeftPadBytes([]byte{0}, 32)) + _, secondCreatedAddress, _ := storage.Get(word256.LeftPadBytes([]byte{0}, 32)) if bytes.Equal(firstCreatedAddress, secondCreatedAddress) { t.Errorf("Multiple contracts created with the same address!") @@ -507,7 +519,7 @@ func TestContractSend(t *testing.T) { newAcc1.Code = callerCode state.UpdateAccount(newAcc1) - sendData = append(sendData, common.LeftPadBytes(acc2.Address, 32)...) + sendData = append(sendData, word256.LeftPadBytes(acc2.Address, 32)...) sendAmt := int64(10) acc2Balance := acc2.Balance diff --git a/manager/eris-mint/state/tx_cache.go b/manager/eris-mint/state/tx_cache.go index 858dc68d719d945588315b2c050c3bc3e99dba44..810e85c9765a8dd84a39d0360c82f16dcb002135 100644 --- a/manager/eris-mint/state/tx_cache.go +++ b/manager/eris-mint/state/tx_cache.go @@ -1,12 +1,29 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( + "fmt" + acm "github.com/eris-ltd/eris-db/account" + "github.com/eris-ltd/eris-db/common/sanity" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" ptypes "github.com/eris-ltd/eris-db/permission/types" // for GlobalPermissionAddress ... "github.com/eris-ltd/eris-db/txs" + . "github.com/eris-ltd/eris-db/word256" - . "github.com/tendermint/go-common" "github.com/tendermint/go-crypto" ) @@ -16,6 +33,8 @@ type TxCache struct { storages map[Tuple256]Word256 } +var _ vm.AppState = &TxCache{} + func NewTxCache(backend *BlockCache) *TxCache { return &TxCache{ backend: backend, @@ -44,7 +63,7 @@ func (cache *TxCache) UpdateAccount(acc *vm.Account) { addr := acc.Address _, removed := cache.accounts[addr].unpack() if removed { - PanicSanity("UpdateAccount on a removed account") + sanity.PanicSanity("UpdateAccount on a removed account") } cache.accounts[addr] = vmAccountInfo{acc, false} } @@ -53,7 +72,7 @@ func (cache *TxCache) RemoveAccount(acc *vm.Account) { addr := acc.Address _, removed := cache.accounts[addr].unpack() if removed { - PanicSanity("RemoveAccount on a removed account") + sanity.PanicSanity("RemoveAccount on a removed account") } cache.accounts[addr] = vmAccountInfo{acc, true} } @@ -85,7 +104,7 @@ func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account { return account } else { // either we've messed up nonce handling, or sha3 is broken - PanicSanity(Fmt("Could not create account, address already exists: %X", addr)) + sanity.PanicSanity(fmt.Sprintf("Could not create account, address already exists: %X", addr)) return nil } } @@ -109,7 +128,7 @@ func (cache *TxCache) GetStorage(addr Word256, key Word256) Word256 { func (cache *TxCache) SetStorage(addr Word256, key Word256, value Word256) { _, removed := cache.accounts[addr].unpack() if removed { - PanicSanity("SetStorage() on a removed account") + sanity.PanicSanity("SetStorage() on a removed account") } cache.storages[Tuple256{addr, key}] = value } diff --git a/manager/eris-mint/state/tx_cache_test.go b/manager/eris-mint/state/tx_cache_test.go index a943ec72844fa37791c4771d78b5931231512ff4..4b30fa4a866b18475d467d2be8b3555bbba32796 100644 --- a/manager/eris-mint/state/tx_cache_test.go +++ b/manager/eris-mint/state/tx_cache_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 state import ( diff --git a/manager/eris-mint/state/types/genesis.go b/manager/eris-mint/state/types/genesis.go deleted file mode 100644 index 806d701b29b2ce0daf3e9f5d99862917e7f8b5db..0000000000000000000000000000000000000000 --- a/manager/eris-mint/state/types/genesis.go +++ /dev/null @@ -1,61 +0,0 @@ -package types - -import ( - "time" - - ptypes "github.com/eris-ltd/eris-db/permission/types" - . "github.com/tendermint/go-common" - "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire" -) - -//------------------------------------------------------------ -// we store the gendoc in the db - -var GenDocKey = []byte("GenDocKey") - -//------------------------------------------------------------ -// core types for a genesis definition - -type BasicAccount struct { - Address []byte `json:"address"` - Amount int64 `json:"amount"` -} - -type GenesisAccount struct { - Address []byte `json:"address"` - Amount int64 `json:"amount"` - Name string `json:"name"` - Permissions *ptypes.AccountPermissions `json:"permissions"` -} - -type GenesisValidator struct { - PubKey crypto.PubKey `json:"pub_key"` - Amount int64 `json:"amount"` - Name string `json:"name"` - UnbondTo []BasicAccount `json:"unbond_to"` -} - -type GenesisParams struct { - GlobalPermissions *ptypes.AccountPermissions `json:"global_permissions"` -} - -type GenesisDoc struct { - GenesisTime time.Time `json:"genesis_time"` - ChainID string `json:"chain_id"` - Params *GenesisParams `json:"params"` - Accounts []GenesisAccount `json:"accounts"` - Validators []GenesisValidator `json:"validators"` -} - -//------------------------------------------------------------ -// Make genesis state from file - -func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) { - var err error - wire.ReadJSONPtr(&genState, jsonBlob, &err) - if err != nil { - Exit(Fmt("Couldn't read GenesisDoc: %v", err)) - } - return -} diff --git a/manager/eris-mint/transactor.go b/manager/eris-mint/transactor.go index 953c519f45a77caac632cbcefb0b5b35dacc9e2b..c29f51b59b7b27a31d3346a575827f034a053ae9 100644 --- a/manager/eris-mint/transactor.go +++ b/manager/eris-mint/transactor.go @@ -1,21 +1,17 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// Transactor is part of the pipe for ErisMint and provides the implementation -// for the pipe to call into the ErisMint application package erismint import ( @@ -25,18 +21,20 @@ import ( "sync" "time" - cmn "github.com/tendermint/go-common" - "github.com/tendermint/go-crypto" - tEvents "github.com/tendermint/go-events" - "github.com/eris-ltd/eris-db/account" core_types "github.com/eris-ltd/eris-db/core/types" event "github.com/eris-ltd/eris-db/event" "github.com/eris-ltd/eris-db/manager/eris-mint/evm" "github.com/eris-ltd/eris-db/manager/eris-mint/state" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/word256" + + "github.com/tendermint/go-crypto" + tEvents "github.com/tendermint/go-events" ) +// Transactor is part of the pipe for ErisMint and provides the implementation +// for the pipe to call into the ErisMint application type transactor struct { chainID string eventSwitch tEvents.Fireable @@ -77,12 +75,12 @@ func (this *transactor) Call(fromAddress, toAddress, data []byte) ( fromAddress = []byte{} } callee := toVMAccount(outAcc) - caller := &vm.Account{Address: cmn.LeftPadWord256(fromAddress)} + caller := &vm.Account{Address: word256.LeftPadWord256(fromAddress)} txCache := state.NewTxCache(cache) gasLimit := st.GetGasLimit() params := vm.Params{ BlockHeight: int64(st.LastBlockHeight), - BlockHash: cmn.LeftPadWord256(st.LastBlockHash), + BlockHash: word256.LeftPadWord256(st.LastBlockHash), BlockTime: st.LastBlockTime.Unix(), GasLimit: gasLimit, } @@ -108,14 +106,14 @@ func (this *transactor) CallCode(fromAddress, code, data []byte) ( fromAddress = []byte{} } cache := this.erisMint.GetCheckCache() // XXX: DON'T MUTATE THIS CACHE (used internally for CheckTx) - callee := &vm.Account{Address: cmn.LeftPadWord256(fromAddress)} - caller := &vm.Account{Address: cmn.LeftPadWord256(fromAddress)} + callee := &vm.Account{Address: word256.LeftPadWord256(fromAddress)} + caller := &vm.Account{Address: word256.LeftPadWord256(fromAddress)} txCache := state.NewTxCache(cache) st := this.erisMint.GetState() // for block height, time gasLimit := st.GetGasLimit() params := vm.Params{ BlockHeight: int64(st.LastBlockHeight), - BlockHash: cmn.LeftPadWord256(st.LastBlockHash), + BlockHash: word256.LeftPadWord256(st.LastBlockHash), BlockTime: st.LastBlockTime.Unix(), GasLimit: gasLimit, } @@ -424,7 +422,7 @@ func (this *transactor) SignTx(tx txs.Tx, privAccounts []*account.PrivAccount) ( // No idea what this does. func toVMAccount(acc *account.Account) *vm.Account { return &vm.Account{ - Address: cmn.LeftPadWord256(acc.Address), + Address: word256.LeftPadWord256(acc.Address), Balance: acc.Balance, Code: acc.Code, Nonce: int64(acc.Sequence), diff --git a/manager/eris-mint/version.go b/manager/eris-mint/version.go index ad15d4a34d7cf0b2eb78a32d4831194e6db9aeb6..6c2ec28da61f6bd4012f9bf47699f6b6aa33f686 100644 --- a/manager/eris-mint/version.go +++ b/manager/eris-mint/version.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 erismint diff --git a/manager/manager.go b/manager/manager.go index 6f71aefa92dfe857cc4bf8d65b9c3cb22fae6eac..e7c1a76187e9229f5dcf2b6b15f697226a3e3076 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 manager diff --git a/manager/types/application.go b/manager/types/application.go index cfcf2b82cc35cfc01c6b9da487f6908143183534..a7594f5c46e134119e8d697841a2b6d629ba006c 100644 --- a/manager/types/application.go +++ b/manager/types/application.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 types diff --git a/permission/types/errors.go b/permission/types/errors.go index 4b1d7cb945a40bcc614546ea08587c6478c90c23..fe023ca8e4a2a4e0817a9a85961981b5f8dba745 100644 --- a/permission/types/errors.go +++ b/permission/types/errors.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( diff --git a/permission/types/permissions.go b/permission/types/permissions.go index 5cdcdaf8ca1e8ba4f5a2e605ed90f3521c757740..94f31e31888311f1bc21a2b3d9771b8b191d071d 100644 --- a/permission/types/permissions.go +++ b/permission/types/permissions.go @@ -1,16 +1,31 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( "fmt" + "strings" - . "github.com/tendermint/go-common" + "github.com/eris-ltd/eris-db/word256" ) //------------------------------------------------------------------------------------------------ var ( - GlobalPermissionsAddress = Zero256[:20] - GlobalPermissionsAddress256 = Zero256 + GlobalPermissionsAddress = word256.Zero256[:20] + GlobalPermissionsAddress256 = word256.Zero256 ) // A particular permission @@ -112,6 +127,12 @@ func (p *BasePermissions) IsSet(ty PermFlag) bool { return p.SetBit&ty > 0 } +// Returns the Perms PermFlag masked with SetBit bit field to give the resultant +// permissions enabled by this BasePermissions +func (p *BasePermissions) ResultantPerms() PermFlag { + return p.Perms & p.SetBit +} + func (p BasePermissions) String() string { return fmt.Sprintf("Base: %b; Set: %b", p.Perms, p.SetBit) } @@ -125,7 +146,7 @@ type AccountPermissions struct { // Returns true if the role is found func (aP *AccountPermissions) HasRole(role string) bool { - role = string(RightPadBytes([]byte(role), 32)) + role = string(word256.RightPadBytes([]byte(role), 32)) for _, r := range aP.Roles { if r == role { return true @@ -136,7 +157,7 @@ func (aP *AccountPermissions) HasRole(role string) bool { // Returns true if the role is added, and false if it already exists func (aP *AccountPermissions) AddRole(role string) bool { - role = string(RightPadBytes([]byte(role), 32)) + role = string(word256.RightPadBytes([]byte(role), 32)) for _, r := range aP.Roles { if r == role { return false @@ -148,7 +169,7 @@ func (aP *AccountPermissions) AddRole(role string) bool { // Returns true if the role is removed, and false if it is not found func (aP *AccountPermissions) RmRole(role string) bool { - role = string(RightPadBytes([]byte(role), 32)) + role = string(word256.RightPadBytes([]byte(role), 32)) for i, r := range aP.Roles { if r == role { post := []string{} @@ -162,6 +183,21 @@ func (aP *AccountPermissions) RmRole(role string) bool { return false } +// Clone clones the account permissions +func (accountPermissions *AccountPermissions) Clone() AccountPermissions { + // clone base permissions + basePermissionsClone := accountPermissions.Base + // clone roles []string + rolesClone := make([]string, len(accountPermissions.Roles)) + // strings are immutable so copy suffices + copy(rolesClone, accountPermissions.Roles) + + return AccountPermissions{ + Base: basePermissionsClone, + Roles: rolesClone, + } +} + //-------------------------------------------------------------------------------- // string utilities @@ -183,54 +219,56 @@ func PermFlagToString(pf PermFlag) (perm string) { case Name: perm = "name" case HasBase: - perm = "has_base" + perm = "hasBase" case SetBase: - perm = "set_base" + perm = "setBase" case UnsetBase: - perm = "unset_base" + perm = "unsetBase" case SetGlobal: - perm = "set_global" + perm = "setGlobal" case HasRole: - perm = "has_role" + perm = "hasRole" case AddRole: - perm = "add_role" + perm = "addRole" case RmRole: - perm = "rm_role" + perm = "removeRole" default: perm = "#-UNKNOWN-#" } return } +// PermStringToFlag maps camel- and snake case strings to the +// the corresponding permission flag. func PermStringToFlag(perm string) (pf PermFlag, err error) { - switch perm { + switch strings.ToLower(perm) { case "root": pf = Root case "send": pf = Send case "call": pf = Call - case "create_contract": + case "createcontract", "create_contract": pf = CreateContract - case "create_account": + case "createaccount", "create_account": pf = CreateAccount case "bond": pf = Bond case "name": pf = Name - case "has_base": + case "hasbase", "has_base": pf = HasBase - case "set_base": + case "setbase", "set_base": pf = SetBase - case "unset_base": + case "unsetbase", "unset_base": pf = UnsetBase - case "set_global": + case "setglobal", "set_global": pf = SetGlobal - case "has_role": + case "hasrole", "has_role": pf = HasRole - case "add_role": + case "addrole", "add_role": pf = AddRole - case "rm_role": + case "removerole", "rmrole", "rm_role": pf = RmRole default: err = fmt.Errorf("Unknown permission %s", perm) diff --git a/permission/types/snatives.go b/permission/types/snatives.go index 57315ac937f1c6a58a97410d3f8fe5a0045b3dcd..f7fe543affd37a0435192f10490db99aa89ffdfd 100644 --- a/permission/types/snatives.go +++ b/permission/types/snatives.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( @@ -25,6 +39,10 @@ const ( PermArgsTypeRmRole = byte(0x07) ) +// TODO: [ben] this registration needs to be lifted up +// and centralised in core; here it pulls in go-wire dependency +// while it suffices to have the type bytes defined; +// --- // for wire.readReflect var _ = wire.RegisterInterface( struct{ PermArgs }{}, diff --git a/permission/types/util.go b/permission/types/util.go new file mode 100644 index 0000000000000000000000000000000000000000..fddf0b9eb2b161b1f4df36733afcba29c429ae75 --- /dev/null +++ b/permission/types/util.go @@ -0,0 +1,49 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types + +// ConvertMapStringIntToPermissions converts a map of string-integer pairs and a slice of +// strings for the roles to an AccountPermissions type. The integer needs to be greater +// than zero to set the permission. For all unmentioned permissions the ZeroBasePermissions +// is defaulted to. +// TODO: [ben] re-evaluate the use of int for setting the permission. +func ConvertPermissionsMapAndRolesToAccountPermissions(permissions map[string]int, roles []string) (*AccountPermissions, error) { + var err error + accountPermissions := &AccountPermissions{} + accountPermissions.Base, err = convertPermissionsMapStringIntToBasePermissions(permissions) + if err != nil { + return nil, err + } + accountPermissions.Roles = roles + return accountPermissions, nil +} + +// convertPermissionsMapStringIntToBasePermissions converts a map of string-integer pairs to +// BasePermissions. +func convertPermissionsMapStringIntToBasePermissions(permissions map[string]int) (BasePermissions, error) { + // initialise basePermissions as ZeroBasePermissions + basePermissions := ZeroBasePermissions + + for permissionName, value := range permissions { + permissionsFlag, err := PermStringToFlag(permissionName) + if err != nil { + return basePermissions, err + } + // sets the permissions bitflag and the setbit flag for the permission. + basePermissions.Set(permissionsFlag, value > 0) + } + + return basePermissions, nil +} diff --git a/rpc/codec.go b/rpc/codec.go index 7afe5a393cd4bc4ad4662cc8d7eaa64a2fd6f654..bbf0ba604183cc0da6be98b0c0909181c9ba9773 100644 --- a/rpc/codec.go +++ b/rpc/codec.go @@ -1,17 +1,16 @@ -// Copyright 2015-2017 Monax Industries Limited. -// This file is part of the Monax platform (Monax) - -// Monax is free software: you can use, redistribute it and/or modify -// it only under the terms of the GNU General Public License, version -// 3, as published by the Free Software Foundation. - -// Monax is distributed WITHOUT ANY WARRANTY pursuant to -// the terms of the Gnu General Public Licence, version 3, including -// (but not limited to) Clause 15 thereof. See the text of the -// GNU General Public License, version 3 for full terms. - -// You should have received a copy of the GNU General Public License, -// version 3, with Monax. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc diff --git a/rpc/jsonrpc.go b/rpc/jsonrpc.go index 73cb0cb6b78862227ecc27afb98bc1f7423244c7..fc04317a43ebd77faa3850e9f781fedb1e627143 100644 --- a/rpc/jsonrpc.go +++ b/rpc/jsonrpc.go @@ -1,17 +1,16 @@ -// Copyright 2015-2017 Monax Industries Limited. -// This file is part of the Monax platform (Monax) - -// Monax is free software: you can use, redistribute it and/or modify -// it only under the terms of the GNU General Public License, version -// 3, as published by the Free Software Foundation. - -// Monax is distributed WITHOUT ANY WARRANTY pursuant to -// the terms of the Gnu General Public Licence, version 3, including -// (but not limited to) Clause 15 thereof. See the text of the -// GNU General Public License, version 3 for full terms. - -// You should have received a copy of the GNU General Public License, -// version 3, with Monax. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc diff --git a/rpc/rpc_test.go b/rpc/rpc_test.go index a63a155101009371cdeec9f8dd7b1a7535e03fec..fbdfca374c8cd4a764ea064d06e74ce5b5ca0e4b 100644 --- a/rpc/rpc_test.go +++ b/rpc/rpc_test.go @@ -1,17 +1,16 @@ -// Copyright 2015-2017 Monax Industries Limited. -// This file is part of the Monax platform (Monax) - -// Monax is free software: you can use, redistribute it and/or modify -// it only under the terms of the GNU General Public License, version -// 3, as published by the Free Software Foundation. - -// Monax is distributed WITHOUT ANY WARRANTY pursuant to -// the terms of the Gnu General Public Licence, version 3, including -// (but not limited to) Clause 15 thereof. See the text of the -// GNU General Public License, version 3 for full terms. - -// You should have received a copy of the GNU General Public License, -// version 3, with Monax. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc diff --git a/rpc/tendermint/client/client.go b/rpc/tendermint/client/client.go index 3afe9c606858987803a5a928f69955880781b60a..978c5a1fd99fcbf28f56e86ed0de3b629d7df656 100644 --- a/rpc/tendermint/client/client.go +++ b/rpc/tendermint/client/client.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 client import ( diff --git a/rpc/tendermint/client/client_test.go b/rpc/tendermint/client/client_test.go index 3fe36f9795c6fe4fd68b6935ba33bf73f690b2b4..105a9d2b92fddd75508c9eadbe209859fbf88b44 100644 --- a/rpc/tendermint/client/client_test.go +++ b/rpc/tendermint/client/client_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 client import ( diff --git a/rpc/tendermint/core/routes.go b/rpc/tendermint/core/routes.go index 718c628ec7d3bb15f03ccc03f2d2cf68cf27c388..76df394f4c144ee0eb41a7fce621a9623c489470 100644 --- a/rpc/tendermint/core/routes.go +++ b/rpc/tendermint/core/routes.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 core import ( diff --git a/rpc/tendermint/core/types/responses.go b/rpc/tendermint/core/types/responses.go index 98b72fbbd200d120c46c834a02d5cc237ff6b5a4..7fcc7ebc326e683acf6330262c2e3fdac827271c 100644 --- a/rpc/tendermint/core/types/responses.go +++ b/rpc/tendermint/core/types/responses.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( diff --git a/rpc/tendermint/core/types/responses_test.go b/rpc/tendermint/core/types/responses_test.go index bf009eab11b57c3dd3df384f8cf903c3ae2f01a4..73e5e97d98d603bebe019042cf7992e569121db0 100644 --- a/rpc/tendermint/core/types/responses_test.go +++ b/rpc/tendermint/core/types/responses_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 types import ( diff --git a/rpc/tendermint/core/types/responses_util.go b/rpc/tendermint/core/types/responses_util.go index 13b21a1451f404e9b681a6699b256138ab3ebbe9..6e0bf52eae97e0795b4f4e4612cea5251e88aaa4 100644 --- a/rpc/tendermint/core/types/responses_util.go +++ b/rpc/tendermint/core/types/responses_util.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 types diff --git a/rpc/tendermint/core/websocket.go b/rpc/tendermint/core/websocket.go index 6824b78e052becb787ccf8092870cb4a73b37c2a..94f55b7895306164a5c9f83b98080fab18d514b2 100644 --- a/rpc/tendermint/core/websocket.go +++ b/rpc/tendermint/core/websocket.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 core diff --git a/rpc/tendermint/test/common.go b/rpc/tendermint/test/common.go index a060833c5091b00156e855c70a276753115d925f..fa16978dab9baf9ac30206314ca89d0230d28faf 100644 --- a/rpc/tendermint/test/common.go +++ b/rpc/tendermint/test/common.go @@ -1,6 +1,20 @@ // +build integration // Space above here matters +// Copyright 2017 Monax Industries Limited +// +// 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 test import ( diff --git a/rpc/tendermint/test/common_test.go b/rpc/tendermint/test/common_test.go index aabfc84f3388060f1831a623812e097eef74dbf2..5b2a1455c161aa75320800e5c89180554b91e1f5 100644 --- a/rpc/tendermint/test/common_test.go +++ b/rpc/tendermint/test/common_test.go @@ -1,6 +1,20 @@ // +build integration // Space above here matters +// Copyright 2017 Monax Industries Limited +// +// 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 test import ( diff --git a/rpc/tendermint/test/config.go b/rpc/tendermint/test/config.go index fcf964bbfc7c0b53183c8838dd521b822eb84a31..96755d4276ef2c27f3f01ed2fada3503c7367fc6 100644 --- a/rpc/tendermint/test/config.go +++ b/rpc/tendermint/test/config.go @@ -1,20 +1,32 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 test -var defaultConfig = `# Copyright 2015, 2016 Eris Industries (UK) Ltd. -# This file is part of Eris-RT -# -# Eris-RT is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +var defaultConfig = `# Copyright 2017 Monax Industries Limited +# +# 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 # -# Eris-RT is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# http://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +# 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.. # This is a TOML configuration for Eris-DB chains diff --git a/rpc/tendermint/test/genesis.go b/rpc/tendermint/test/genesis.go index 3136a9339323cbfd1f5508daae335de335c9ef10..9ca0e6e83c0575b733b841f0af44402adc83d19d 100644 --- a/rpc/tendermint/test/genesis.go +++ b/rpc/tendermint/test/genesis.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 test // priv keys generated deterministically eg rpc/tests/shared.go diff --git a/rpc/tendermint/test/rpc_client_test.go b/rpc/tendermint/test/rpc_client_test.go index 7183f2df8f1effbafe76705e344fd1658c01852a..0dcfad967b56a78d244f4834c812d39d3c54253a 100644 --- a/rpc/tendermint/test/rpc_client_test.go +++ b/rpc/tendermint/test/rpc_client_test.go @@ -1,22 +1,35 @@ // +build integration // Space above here matters +// Copyright 2017 Monax Industries Limited +// +// 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 test import ( "bytes" "fmt" - "testing" - "golang.org/x/crypto/ripemd160" - + "testing" "time" consensus_types "github.com/eris-ltd/eris-db/consensus/types" edbcli "github.com/eris-ltd/eris-db/rpc/tendermint/client" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/word256" + "github.com/stretchr/testify/assert" - tm_common "github.com/tendermint/go-common" rpcclient "github.com/tendermint/go-rpc/client" _ "github.com/tendermint/tendermint/config/tendermint_test" ) @@ -123,8 +136,8 @@ func TestGetStorage(t *testing.T) { " created a contract but the contract address is empty") v := getStorage(t, client, contractAddr, []byte{0x1}) - got := tm_common.LeftPadWord256(v) - expected := tm_common.LeftPadWord256([]byte{0x5}) + got := word256.LeftPadWord256(v) + expected := word256.LeftPadWord256([]byte{0x5}) if got.Compare(expected) != 0 { t.Fatalf("Wrong storage value. Got %x, expected %x", got.Bytes(), expected.Bytes()) @@ -148,8 +161,8 @@ func TestCallCode(t *testing.T) { // pass two ints as calldata, add, and return the result code = []byte{0x60, 0x0, 0x35, 0x60, 0x20, 0x35, 0x1, 0x60, 0x0, 0x52, 0x60, 0x20, 0x60, 0x0, 0xf3} - data = append(tm_common.LeftPadWord256([]byte{0x5}).Bytes(), - tm_common.LeftPadWord256([]byte{0x6}).Bytes()...) + data = append(word256.LeftPadWord256([]byte{0x5}).Bytes(), + word256.LeftPadWord256([]byte{0x6}).Bytes()...) expected = []byte{0xb} callCode(t, client, user[0].PubKey.Address(), code, data, expected) }) diff --git a/rpc/tendermint/test/runner/main.go b/rpc/tendermint/test/runner/main.go index a6836357833531d32e6218ff5001b58adb37505e..a47649dad23f61cb7c4457c3499896984182014b 100644 --- a/rpc/tendermint/test/runner/main.go +++ b/rpc/tendermint/test/runner/main.go @@ -1,6 +1,20 @@ // +build integration // Space above here matters +// Copyright 2017 Monax Industries Limited +// +// 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 main import ( diff --git a/rpc/tendermint/test/shared.go b/rpc/tendermint/test/shared.go index 8c01b6a2f024d402cbea6dc1e7cea5f54dbf7f7e..98044412e36986d6cbf302c75b1fc6b21e4d9c9c 100644 --- a/rpc/tendermint/test/shared.go +++ b/rpc/tendermint/test/shared.go @@ -1,30 +1,42 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 test import ( "bytes" "hash/fnv" + "path" "strconv" "testing" acm "github.com/eris-ltd/eris-db/account" "github.com/eris-ltd/eris-db/core" core_types "github.com/eris-ltd/eris-db/core/types" + "github.com/eris-ltd/eris-db/logging/lifecycle" edbcli "github.com/eris-ltd/eris-db/rpc/tendermint/client" rpc_core "github.com/eris-ltd/eris-db/rpc/tendermint/core" rpc_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" "github.com/eris-ltd/eris-db/server" "github.com/eris-ltd/eris-db/test/fixtures" "github.com/eris-ltd/eris-db/txs" + "github.com/eris-ltd/eris-db/word256" + genesis "github.com/eris-ltd/eris-db/genesis" + "github.com/spf13/viper" "github.com/tendermint/go-crypto" rpcclient "github.com/tendermint/go-rpc/client" - - "path" - - "github.com/eris-ltd/eris-db/logging/lifecycle" - state_types "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" - "github.com/spf13/viper" - tm_common "github.com/tendermint/go-common" "github.com/tendermint/tendermint/types" ) @@ -35,7 +47,7 @@ var ( mempoolCount = 0 chainID string websocketAddr string - genesisDoc *state_types.GenesisDoc + genesisDoc *genesis.GenesisDoc websocketEndpoint string user = makeUsers(5) // make keys jsonRpcClient rpcclient.Client @@ -50,7 +62,7 @@ func initGlobalVariables(ffs *fixtures.FileFixtures) error { rootWorkDir = ffs.AddDir("rootWorkDir") rootDataDir := ffs.AddDir("rootDataDir") genesisFile := ffs.AddFile("rootWorkDir/genesis.json", defaultGenesis) - genesisDoc = state_types.GenesisDocFromJSON([]byte(defaultGenesis)) + genesisDoc = genesis.GenesisDocFromJSON([]byte(defaultGenesis)) if ffs.Error != nil { return ffs.Error @@ -242,7 +254,7 @@ func callCode(t *testing.T, client rpcclient.Client, fromAddress, code, data, } ret := resp.Return // NOTE: we don't flip memory when it comes out of RETURN (?!) - if bytes.Compare(ret, tm_common.LeftPadWord256(expected).Bytes()) != 0 { + if bytes.Compare(ret, word256.LeftPadWord256(expected).Bytes()) != 0 { t.Fatalf("Conflicting return value. Got %x, expected %x", ret, expected) } } @@ -255,7 +267,7 @@ func callContract(t *testing.T, client rpcclient.Client, fromAddress, toAddress, } ret := resp.Return // NOTE: we don't flip memory when it comes out of RETURN (?!) - if bytes.Compare(ret, tm_common.LeftPadWord256(expected).Bytes()) != 0 { + if bytes.Compare(ret, word256.LeftPadWord256(expected).Bytes()) != 0 { t.Fatalf("Conflicting return value. Got %x, expected %x", ret, expected) } } @@ -294,14 +306,14 @@ func simpleContract() ([]byte, []byte, []byte) { // push code to the stack //code := append([]byte{byte(0x60 + lenCode - 1)}, RightPadWord256(contractCode).Bytes()...) code := append([]byte{0x7f}, - tm_common.RightPadWord256(contractCode).Bytes()...) + word256.RightPadWord256(contractCode).Bytes()...) // store it in memory code = append(code, []byte{0x60, 0x0, 0x52}...) // return whats in memory //code = append(code, []byte{0x60, byte(32 - lenCode), 0x60, byte(lenCode), 0xf3}...) code = append(code, []byte{0x60, byte(lenCode), 0x60, 0x0, 0xf3}...) // return init code, contract code, expected return - return code, contractCode, tm_common.LeftPadBytes([]byte{0xb}, 32) + return code, contractCode, word256.LeftPadBytes([]byte{0xb}, 32) } // simple call contract calls another contract @@ -329,5 +341,5 @@ func simpleCallContract(addr []byte) ([]byte, []byte, []byte) { code = append(code, []byte{0x60, byte(lenCode), 0x60, 0x0, 0xf3}...) code = append(code, contractCode...) // return init code, contract code, expected return - return code, contractCode, tm_common.LeftPadBytes([]byte{0xb}, 32) + return code, contractCode, word256.LeftPadBytes([]byte{0xb}, 32) } diff --git a/rpc/tendermint/test/websocket_client_test.go b/rpc/tendermint/test/websocket_client_test.go index 60e665bdce2a2ecfdf4791deec6c75672446523c..5f799041f652d2425611c474e78faff6970141ab 100644 --- a/rpc/tendermint/test/websocket_client_test.go +++ b/rpc/tendermint/test/websocket_client_test.go @@ -1,6 +1,20 @@ // +build integration // Space above here matters +// Copyright 2017 Monax Industries Limited +// +// 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 test import ( diff --git a/rpc/tendermint/test/websocket_helpers.go b/rpc/tendermint/test/websocket_helpers.go index b5a7f79f002d54601677142adc8fd82d991df8ba..46408e5d42fd1e9ab3d9d27d7cc0bb5d0353a27c 100644 --- a/rpc/tendermint/test/websocket_helpers.go +++ b/rpc/tendermint/test/websocket_helpers.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 test import ( diff --git a/rpc/v0/codec.go b/rpc/v0/codec.go index 1fd379bea6e5e330827421c9a56813ea165d0d76..5763c7bc710adfcc897cb581a25da5596026f27c 100644 --- a/rpc/v0/codec.go +++ b/rpc/v0/codec.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 rpc_v0 diff --git a/rpc/v0/json_service.go b/rpc/v0/json_service.go index ab4ce33f60b0be23622fc83b594d5005d48745f9..77bc4ffaa32a8c6e6e6f38104ecf440494b5951e 100644 --- a/rpc/v0/json_service.go +++ b/rpc/v0/json_service.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 rpc_v0 import ( diff --git a/rpc/v0/methods.go b/rpc/v0/methods.go index eaa82ff06eda12db9a282e62de845b0fc506df22..cc0a040aed6c92ecaf60fd8522f178457458ec3e 100644 --- a/rpc/v0/methods.go +++ b/rpc/v0/methods.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 rpc_v0 import ( diff --git a/rpc/v0/params.go b/rpc/v0/params.go index 98778554dec9a3a2329d0d591b8cd5b05f21e12f..e6f565557ea65247391e8532b282e3fbe80383d8 100644 --- a/rpc/v0/params.go +++ b/rpc/v0/params.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 rpc_v0 import ( diff --git a/rpc/v0/restServer.go b/rpc/v0/restServer.go index 2af84e19e666efc6eb312a40271bced1cf44d5b1..18fb507ec3569df4699af3172eccf7c9d6910471 100644 --- a/rpc/v0/restServer.go +++ b/rpc/v0/restServer.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 rpc_v0 import ( diff --git a/rpc/v0/shared/net.go b/rpc/v0/shared/net.go index 778b53595bc34896d54c61fc7cbe95029c4eb0ba..5d1bc85dca44f2a16b709592430d728735bf754b 100644 --- a/rpc/v0/shared/net.go +++ b/rpc/v0/shared/net.go @@ -1,21 +1,17 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. - -// Net is part of the pipe for ErisMint and provides the implementation -// for the pipe to call into the ErisMint application package shared import ( @@ -23,6 +19,9 @@ import ( "github.com/eris-ltd/eris-db/definitions" ) +// Net is part of the pipe for ErisMint and provides the implementation +// for the pipe to call into the ErisMint application + //----------------------------------------------------------------------------- // Get the complete pipe info. diff --git a/rpc/v0/shared/pipes.go b/rpc/v0/shared/pipes.go index fb71aad9abe1006a233e60cb1f12bf048ad2d6a9..55a27b3fb493c2a3aad54bad996dc842c1073f7a 100644 --- a/rpc/v0/shared/pipes.go +++ b/rpc/v0/shared/pipes.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 shared // Shared extension methods for Pipe and its derivatives diff --git a/rpc/v0/wsService.go b/rpc/v0/wsService.go index c7e89ff5b5950ea0900471ed971dd5f26c6c23f8..daea0d01b75844cf3d19aaba958ed8bff9cf6308 100644 --- a/rpc/v0/wsService.go +++ b/rpc/v0/wsService.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 rpc_v0 import ( diff --git a/server/config.go b/server/config.go index 13078f985532f58ffa073c3fd9829f93a057ef9c..4dcce19dd18199cfbbd19ae0f54bed9554b8db53 100644 --- a/server/config.go +++ b/server/config.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 server diff --git a/server/idpool.go b/server/idpool.go index d713c7014f1abb0da48f9a9e49d9faccc55ac899..44a72cba4d1b3266430b4ff95841a90db4316de8 100644 --- a/server/idpool.go +++ b/server/idpool.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/server/log.go b/server/log.go index aacad33d92109b6353e54b91b438b3f2f7e746f3..e2bcb50b4cbf34e4807fd3bed9c484c1211a23d6 100644 --- a/server/log.go +++ b/server/log.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/server/logging.go b/server/logging.go index 173fecaf34371dea336d152b0d911efac4f7309d..4a38e0f82d039b18400ec07d1767812e1210c574 100644 --- a/server/logging.go +++ b/server/logging.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/server/server.go b/server/server.go index f1d38c3dea5fdd2c1c9fb4ed949c52df44f78998..8e4c85122e663417e9355b099c9153442f70f9ae 100644 --- a/server/server.go +++ b/server/server.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/server/server_test.go b/server/server_test.go index 61569515529d3d9d650f018f2757cc0fc371cbe4..5efdad26819e4d2f12ed568c71954eb27ce1405c 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/server/websocket.go b/server/websocket.go index a5767141c8710a3b854f6d3efc35daf2791eb4e5..aff2f94c307aa13c3383292ad9dd44f4b054b8e2 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/test/filters/filter_test.go b/test/filters/filter_test.go index ff57650149d36642806ae17c447c1fb0b594d572..c27a1eb02c3fb267243bbcd3533057b78b379f82 100644 --- a/test/filters/filter_test.go +++ b/test/filters/filter_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 filters import ( diff --git a/test/fixtures/file_fixtures.go b/test/fixtures/file_fixtures.go index da751d108d7a068eef522eabbff92788004096f1..d6926c0972911d33b3f4d3272645388e36bec8bd 100644 --- a/test/fixtures/file_fixtures.go +++ b/test/fixtures/file_fixtures.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 fixtures import ( diff --git a/test/mock/mock_web_api_test.go b/test/mock/mock_web_api_test.go index fc0603e0114ae86d83368a0c6ebfd6cc350b10dc..decf5796d86e96cb9b9dae1f32faec6ed45d67fd 100644 --- a/test/mock/mock_web_api_test.go +++ b/test/mock/mock_web_api_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 mock // Basic imports diff --git a/test/mock/pipe.go b/test/mock/pipe.go index ecd245ec87e2c9934e360ae72869210e134ee820..f208f324cdeca39aeb43a900a6ad177f93a4f1b8 100644 --- a/test/mock/pipe.go +++ b/test/mock/pipe.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 mock import ( diff --git a/test/server/http_burst_test.go b/test/server/http_burst_test.go index bb49275b7d82c5ee10a35fb162a79852e95833eb..b9e404e2801abb98046186e53ca0e9342eec7016 100644 --- a/test/server/http_burst_test.go +++ b/test/server/http_burst_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/test/server/scumbag.go b/test/server/scumbag.go index 71eaddc61d10affad17ad6f9548d42b461b7f172..67751442e23b3b5ad948fb0b88ce33a8758ab9f3 100644 --- a/test/server/scumbag.go +++ b/test/server/scumbag.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/test/server/ws_burst_test.go b/test/server/ws_burst_test.go index cb9e7af4f2037fdc52f4893f464c3436b406cff9..55dd8e93975f923fbefc79d5e2a2eded08be37fd 100644 --- a/test/server/ws_burst_test.go +++ b/test/server/ws_burst_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 server import ( diff --git a/test/testdata/helpers.go b/test/testdata/helpers.go index 127440f7eb185dcd360d13b9dc183c8983dc72ad..2dbbaed7bbd0c3a31c042b3928ede8c39df16bbb 100644 --- a/test/testdata/helpers.go +++ b/test/testdata/helpers.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 testdata import ( diff --git a/test/testdata/testdata/testdata.go b/test/testdata/testdata/testdata.go index 5fd2be000a2773de50fb7e469ed2a08bc820f2a5..2f212de66036c4ef868b75cb74a489602838998b 100644 --- a/test/testdata/testdata/testdata.go +++ b/test/testdata/testdata/testdata.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 testdata import ( @@ -5,7 +19,7 @@ import ( consensus_types "github.com/eris-ltd/eris-db/consensus/types" core_types "github.com/eris-ltd/eris-db/core/types" event "github.com/eris-ltd/eris-db/event" - stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" + genesis "github.com/eris-ltd/eris-db/genesis" rpc_v0 "github.com/eris-ltd/eris-db/rpc/v0" "github.com/eris-ltd/eris-db/rpc/v0/shared" transaction "github.com/eris-ltd/eris-db/txs" @@ -540,7 +554,7 @@ var serverDuration uint = 100 type ( ChainData struct { PrivValidator *mintTypes.PrivValidator `json:"priv_validator"` - Genesis *stypes.GenesisDoc `json:"genesis"` + Genesis *genesis.GenesisDoc `json:"genesis"` } GetAccountData struct { diff --git a/txs/events.go b/txs/events.go index 4cb7e656c6535bebd71088693f4e5b7486cb1f9b..9e15cd3c54b2a3a8c6c5b88dd701f0448da3a9d1 100644 --- a/txs/events.go +++ b/txs/events.go @@ -1,12 +1,26 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 txs import ( "fmt" "time" - . "github.com/tendermint/go-common" - "github.com/tendermint/go-wire" + . "github.com/eris-ltd/eris-db/word256" + "github.com/tendermint/go-wire" tm_types "github.com/tendermint/tendermint/types" // Block ) diff --git a/txs/names.go b/txs/names.go index 1cc00e168c4b3dfce9cb1685969e645caf412d41..41b80b085af1c280cc92eaeed2186508b217be69 100644 --- a/txs/names.go +++ b/txs/names.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 txs import ( diff --git a/txs/tx.go b/txs/tx.go index a216332031d24951fdc63d1f12a57b9f8f932fc7..0a7430dc193b755eb43745d1484043e5c249bce7 100644 --- a/txs/tx.go +++ b/txs/tx.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 txs import ( diff --git a/txs/tx_test.go b/txs/tx_test.go index e3f092da5679bd78f2b0ff1e1a4423f8eb960565..e4b0653dc9472d329b8bbf61646ba3e0eb260e03 100644 --- a/txs/tx_test.go +++ b/txs/tx_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 txs import ( diff --git a/txs/tx_utils.go b/txs/tx_utils.go index cdc4be247762db25b3abccda6919b7f72f594751..0c6466486c03339ff0b2afd94aed2da3cb5a1d56 100644 --- a/txs/tx_utils.go +++ b/txs/tx_utils.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 txs import ( diff --git a/util/architecture/constants.go b/util/architecture/constants.go index fb03311c6b6f1c10f6fa6b2284abb4974183d39f..695a5fe16a76b57f7eb4dafcbda7b3a4194a1bc2 100644 --- a/util/architecture/constants.go +++ b/util/architecture/constants.go @@ -1,5 +1,19 @@ // +build !arm +// Copyright 2017 Monax Industries Limited +// +// 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 architecture import "math" diff --git a/util/architecture/constants_arm.go b/util/architecture/constants_arm.go index 5f8c9cc82ea360956a4206da74f69391e1bb4045..c677498cba7c32836976414bca39d10614319ab2 100644 --- a/util/architecture/constants_arm.go +++ b/util/architecture/constants_arm.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 architecture import "math" diff --git a/util/fs.go b/util/fs.go index 7d41c1ddd51d28de1859daf291062d2afd5d4290..41ec3fce08a181acb8fd806cb99a74fcfb260684 100644 --- a/util/fs.go +++ b/util/fs.go @@ -1,18 +1,16 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT - -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +// Copyright 2017 Monax Industries Limited +// +// 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 util diff --git a/util/hell/cmd/hell/main.go b/util/hell/cmd/hell/main.go index 6736e496f29cb335239c8553117f13df355f588d..8fc417eec070d1a20a2f173fdbe81e5ac0d3717f 100644 --- a/util/hell/cmd/hell/main.go +++ b/util/hell/cmd/hell/main.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 main import ( diff --git a/util/hell/merge.go b/util/hell/merge.go index 915001f398d7fa229df015f4d03e13f2a87ade5a..130a80065b9ba82b70a0cbe24ebac439dd79b974 100644 --- a/util/hell/merge.go +++ b/util/hell/merge.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 hell import ( diff --git a/util/hell/merge_test.go b/util/hell/merge_test.go index df44045a7d6ab111c441bdaa8d6d96e6fcd58517..5fffedb9c93d01cc24782a657a09282d408933a9 100644 --- a/util/hell/merge_test.go +++ b/util/hell/merge_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 hell import ( diff --git a/util/os.go b/util/os.go index cc682918d88264505a5b48ab0d8819ff612d5395..a205c1c0931ab03a6f2577cc2aef979441660730 100644 --- a/util/os.go +++ b/util/os.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 util import ( diff --git a/util/slice/slice.go b/util/slice/slice.go index 2c51efd21f89c3478a185d623e54dcc9d4ea3064..8c2b7f8914b86539c04051f7077830c82ec4b835 100644 --- a/util/slice/slice.go +++ b/util/slice/slice.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 slice func Slice(elements ...interface{}) []interface{} { diff --git a/util/slice/slice_test.go b/util/slice/slice_test.go index b3d1c9b6a530b1fe050427b3ba41ae8f9f23c388..8ab47c99aa03c78a5efcf539807ce68fe3deaa5c 100644 --- a/util/slice/slice_test.go +++ b/util/slice/slice_test.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 slice import ( diff --git a/util/snatives/cmd/main.go b/util/snatives/cmd/main.go new file mode 100644 index 0000000000000000000000000000000000000000..ddf456c21fffee141d735c56297ffe7a81709e07 --- /dev/null +++ b/util/snatives/cmd/main.go @@ -0,0 +1,43 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 main + +import ( + "fmt" + + "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + "github.com/eris-ltd/eris-db/util/snatives/templates" +) + +// Dump SNative contracts +func main() { + contracts := vm.SNativeContracts() + // Index of next contract + i := 1 + for _, contract := range contracts { + solidity, err := templates.NewSolidityContract(contract).Solidity() + if err != nil { + fmt.Printf("Error generating solidity for contract %s: %s\n", + contract.Name, err) + } + fmt.Println(solidity) + if i < len(contracts) { + // Two new lines between contracts as per Solidity style guide + // (the template gives us 1 trailing new line) + fmt.Println() + } + i++ + } +} diff --git a/util/snatives/templates/indent_writer.go b/util/snatives/templates/indent_writer.go new file mode 100644 index 0000000000000000000000000000000000000000..c395f5a9f16da3fae0ce17c4878e3ef38a55eeee --- /dev/null +++ b/util/snatives/templates/indent_writer.go @@ -0,0 +1,61 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 templates + +import "io" + +const newLine = byte('\n') + +type indentWriter struct { + writer io.Writer + indentLevel uint + indentBytes []byte + indent bool +} + +var _ io.Writer = (*indentWriter)(nil) + +// indentWriter indents all lines written to it with a specified indent string +// indented the specified number of indents +func NewIndentWriter(indentLevel uint, indentString string, + writer io.Writer) *indentWriter { + return &indentWriter{ + writer: writer, + indentLevel: indentLevel, + indentBytes: []byte(indentString), + indent: true, + } +} + +func (iw *indentWriter) Write(p []byte) (int, error) { + bs := make([]byte, 0, len(p)) + for _, b := range p { + if iw.indent { + for i := uint(0); i < iw.indentLevel; i++ { + bs = append(bs, iw.indentBytes...) + } + iw.indent = false + } + if b == newLine { + iw.indent = true + } + bs = append(bs, b) + } + return iw.writer.Write(bs) +} + +func (iw *indentWriter) SetIndent(level uint) { + iw.indentLevel = level +} diff --git a/util/snatives/templates/solidity_templates.go b/util/snatives/templates/solidity_templates.go new file mode 100644 index 0000000000000000000000000000000000000000..a0c75d3d8a14ad0fb67524b33086827b01922ef4 --- /dev/null +++ b/util/snatives/templates/solidity_templates.go @@ -0,0 +1,147 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 templates + +import ( + "bytes" + "fmt" + "strings" + "text/template" + + "github.com/eris-ltd/eris-db/manager/eris-mint/evm" +) + +const contractTemplateText = `/** +[[.Comment]] +* @dev These functions can be accessed as if this contract were deployed at the address [[.Address]] +*/ +contract [[.Name]] {[[range .Functions]] +[[.SolidityIndent 1]] +[[end]]} +` +const functionTemplateText = `/** +[[.Comment]] +*/ +function [[.Name]]([[.ArgList]]) constant returns ([[.Return.Type]] [[.Return.Name]]);` + +// Solidity style guide recommends 4 spaces per indentation level +// (see: http://solidity.readthedocs.io/en/develop/style-guide.html) +const indentString = " " + +var contractTemplate *template.Template +var functionTemplate *template.Template + +func init() { + var err error + functionTemplate, err = template.New("SolidityFunctionTemplate"). + Delims("[[", "]]"). + Parse(functionTemplateText) + if err != nil { + panic(fmt.Errorf("Couldn't parse SNative function template: %s", err)) + } + contractTemplate, err = template.New("SolidityContractTemplate"). + Delims("[[", "]]"). + Parse(contractTemplateText) + if err != nil { + panic(fmt.Errorf("Couldn't parse SNative contract template: %s", err)) + } +} + +type solidityContract struct { + *vm.SNativeContractDescription +} + +type solidityFunction struct { + *vm.SNativeFunctionDescription +} + +// Create a templated solidityContract from an SNative contract description +func NewSolidityContract(contract *vm.SNativeContractDescription) *solidityContract { + return &solidityContract{contract} +} + +func (contract *solidityContract) Address() string { + return fmt.Sprintf("0x%x", + contract.SNativeContractDescription.Address().Postfix(20)) +} + +// Generate Solidity code for this SNative contract +func (contract *solidityContract) Solidity() (string, error) { + buf := new(bytes.Buffer) + err := contractTemplate.Execute(buf, contract) + if err != nil { + return "", err + } + return buf.String(), nil +} + +func (contract *solidityContract) Functions() []*solidityFunction { + functions := contract.SNativeContractDescription.Functions() + solidityFunctions := make([]*solidityFunction, len(functions)) + for i, function := range functions { + solidityFunctions[i] = NewSolidityFunction(function) + } + return solidityFunctions +} + +// Create a templated solidityFunction from an SNative function description +func NewSolidityFunction(function *vm.SNativeFunctionDescription) *solidityFunction { + return &solidityFunction{function} +} + +func (function *solidityFunction) ArgList() string { + argList := make([]string, len(function.Args)) + for i, arg := range function.Args { + argList[i] = fmt.Sprintf("%s %s", arg.Type, arg.Name) + } + return strings.Join(argList, ", ") +} + +func (function *solidityFunction) Comment() string { + return comment(function.SNativeFunctionDescription.Comment) +} + +func (function *solidityFunction) SolidityIndent(indentLevel uint) (string, error) { + return function.solidity(indentLevel) +} + +func (function *solidityFunction) Solidity() (string, error) { + return function.solidity(0) +} + +func (function *solidityFunction) solidity(indentLevel uint) (string, error) { + buf := new(bytes.Buffer) + iw := NewIndentWriter(indentLevel, indentString, buf) + err := functionTemplate.Execute(iw, function) + if err != nil { + return "", err + } + return buf.String(), nil +} + +func (contract *solidityContract) Comment() string { + return comment(contract.SNativeContractDescription.Comment) +} + +func comment(comment string) string { + commentLines := make([]string, 0, 5) + for _, line := range strings.Split(comment, "\n") { + trimLine := strings.TrimLeft(line, " \t\n") + if trimLine != "" { + commentLines = append(commentLines, trimLine) + } + } + return strings.Join(commentLines, "\n") +} diff --git a/util/snatives/templates/solidity_templates_test.go b/util/snatives/templates/solidity_templates_test.go new file mode 100644 index 0000000000000000000000000000000000000000..c839230ea3bceb141a2e23de0de865b03dd77bae --- /dev/null +++ b/util/snatives/templates/solidity_templates_test.go @@ -0,0 +1,44 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 templates + +import ( + "fmt" + "github.com/eris-ltd/eris-db/manager/eris-mint/evm" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestSNativeFuncTemplate(t *testing.T) { + contract := vm.SNativeContracts()["Permissions"] + function, err := contract.FunctionByName("removeRole") + if err != nil { + t.Fatal("Couldn't get function") + } + solidityFunction := NewSolidityFunction(function) + solidity, err := solidityFunction.Solidity() + assert.NoError(t, err) + fmt.Println(solidity) +} + +// This test checks that we can generate the SNative contract interface and +// prints it to stdout +func TestSNativeContractTemplate(t *testing.T) { + contract := vm.SNativeContracts()["Permissions"] + solidityContract := NewSolidityContract(contract) + solidity, err := solidityContract.Solidity() + assert.NoError(t, err) + fmt.Println(solidity) +} diff --git a/util/util.go b/util/util.go index c0acaefc64d4b75b74c66a4a3802e9edc0d0385f..d170c681553b6d38206ca86d883c30dba72598a5 100644 --- a/util/util.go +++ b/util/util.go @@ -1,3 +1,17 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 util import ( diff --git a/version/version.go b/version/version.go index 6dfd478df781304268f68cee7a1d944d1b2af103..200259900e2e7d83ccf7963f0560750c2f5ca714 100644 --- a/version/version.go +++ b/version/version.go @@ -1,24 +1,22 @@ -// Copyright 2015, 2016 Eris Industries (UK) Ltd. -// This file is part of Eris-RT +// Copyright 2017 Monax Industries Limited +// +// 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. -// Eris-RT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Eris-RT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. +package version // version provides the current Eris-DB version and a VersionIdentifier // for the modules to identify their version with. -package version - import ( "fmt" ) diff --git a/word256/byteslice.go b/word256/byteslice.go new file mode 100644 index 0000000000000000000000000000000000000000..88dbaf7c8625cbffd3cc2a4936697ae10294a6b8 --- /dev/null +++ b/word256/byteslice.go @@ -0,0 +1,61 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 word256 + +// TODO: [ben] byteslice is not specific for word256, but it is used exclusively +// for word256 (and for word160* 20byte addresses) so consider stronger typing. + +import ( + "bytes" +) + +func Fingerprint(slice []byte) []byte { + fingerprint := make([]byte, 6) + copy(fingerprint, slice) + return fingerprint +} + +func IsZeros(slice []byte) bool { + for _, byt := range slice { + if byt != byte(0) { + return false + } + } + return true +} + +func RightPadBytes(slice []byte, l int) []byte { + if l < len(slice) { + return slice + } + padded := make([]byte, l) + copy(padded[0:len(slice)], slice) + return padded +} + +func LeftPadBytes(slice []byte, l int) []byte { + if l < len(slice) { + return slice + } + padded := make([]byte, l) + copy(padded[l-len(slice):], slice) + return padded +} + +func TrimmedString(b []byte) string { + trimSet := string([]byte{0}) + return string(bytes.TrimLeft(b, trimSet)) + +} diff --git a/word256/int.go b/word256/int.go new file mode 100644 index 0000000000000000000000000000000000000000..7e91add1526de3a818602284ff16062d1fde91fe --- /dev/null +++ b/word256/int.go @@ -0,0 +1,74 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 word256 + +// NOTE: [ben] this used to be in tendermint/go-common but should be +// isolated and cleaned up and tested. Should be used in permissions +// and manager/eris-mint +// TODO: [ben] cleanup, but also write unit-tests + +import ( + "encoding/binary" + "sort" +) + +// Sort for []uint64 + +type Uint64Slice []uint64 + +func (p Uint64Slice) Len() int { return len(p) } +func (p Uint64Slice) Less(i, j int) bool { return p[i] < p[j] } +func (p Uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p Uint64Slice) Sort() { sort.Sort(p) } + +func SearchUint64s(a []uint64, x uint64) int { + return sort.Search(len(a), func(i int) bool { return a[i] >= x }) +} + +func (p Uint64Slice) Search(x uint64) int { return SearchUint64s(p, x) } + +//-------------------------------------------------------------------------------- + +func PutUint64LE(dest []byte, i uint64) { + binary.LittleEndian.PutUint64(dest, i) +} + +func GetUint64LE(src []byte) uint64 { + return binary.LittleEndian.Uint64(src) +} + +func PutUint64BE(dest []byte, i uint64) { + binary.BigEndian.PutUint64(dest, i) +} + +func GetUint64BE(src []byte) uint64 { + return binary.BigEndian.Uint64(src) +} + +func PutInt64LE(dest []byte, i int64) { + binary.LittleEndian.PutUint64(dest, uint64(i)) +} + +func GetInt64LE(src []byte) int64 { + return int64(binary.LittleEndian.Uint64(src)) +} + +func PutInt64BE(dest []byte, i int64) { + binary.BigEndian.PutUint64(dest, uint64(i)) +} + +func GetInt64BE(src []byte) int64 { + return int64(binary.BigEndian.Uint64(src)) +} diff --git a/word256/word.go b/word256/word.go new file mode 100644 index 0000000000000000000000000000000000000000..e5ce7cb7cdd8ad64757700ee80e125a88124f8dd --- /dev/null +++ b/word256/word.go @@ -0,0 +1,112 @@ +// Copyright 2017 Monax Industries Limited +// +// 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 word256 + +// NOTE: [ben] this used to be in tendermint/go-common but should be +// isolated and cleaned up and tested. Should be used in permissions +// and manager/eris-mint +// TODO: [ben] cleanup, but also write unit-tests + +import ( + "bytes" + "sort" +) + +var ( + Zero256 = Word256{0} + One256 = Word256{1} +) + +const Word256Length = 32 + +type Word256 [Word256Length]byte + +func (w Word256) String() string { return string(w[:]) } +func (w Word256) TrimmedString() string { return TrimmedString(w.Bytes()) } +func (w Word256) Copy() Word256 { return w } +func (w Word256) Bytes() []byte { return w[:] } // copied. +func (w Word256) Prefix(n int) []byte { return w[:n] } +func (w Word256) Postfix(n int) []byte { return w[32-n:] } +func (w Word256) IsZero() bool { + accum := byte(0) + for _, byt := range w { + accum |= byt + } + return accum == 0 +} +func (w Word256) Compare(other Word256) int { + return bytes.Compare(w[:], other[:]) +} + +func Uint64ToWord256(i uint64) Word256 { + buf := [8]byte{} + PutUint64BE(buf[:], i) + return LeftPadWord256(buf[:]) +} + +func Int64ToWord256(i int64) Word256 { + buf := [8]byte{} + PutInt64BE(buf[:], i) + return LeftPadWord256(buf[:]) +} + +func RightPadWord256(bz []byte) (word Word256) { + copy(word[:], bz) + return +} + +func LeftPadWord256(bz []byte) (word Word256) { + copy(word[32-len(bz):], bz) + return +} + +func Uint64FromWord256(word Word256) uint64 { + buf := word.Postfix(8) + return GetUint64BE(buf) +} + +func Int64FromWord256(word Word256) int64 { + buf := word.Postfix(8) + return GetInt64BE(buf) +} + +//------------------------------------- + +type Tuple256 struct { + First Word256 + Second Word256 +} + +func (tuple Tuple256) Compare(other Tuple256) int { + firstCompare := tuple.First.Compare(other.First) + if firstCompare == 0 { + return tuple.Second.Compare(other.Second) + } else { + return firstCompare + } +} + +func Tuple256Split(t Tuple256) (Word256, Word256) { + return t.First, t.Second +} + +type Tuple256Slice []Tuple256 + +func (p Tuple256Slice) Len() int { return len(p) } +func (p Tuple256Slice) Less(i, j int) bool { + return p[i].Compare(p[j]) < 0 +} +func (p Tuple256Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p Tuple256Slice) Sort() { sort.Sort(p) }