mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Renme BigchainDB to CoreChainDB
This commit is contained in:
parent
3c89d306ef
commit
f8a00d7f62
@ -10,5 +10,5 @@ set -e -x
|
||||
if [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
|
||||
sleep 3600
|
||||
else
|
||||
bigchaindb -l DEBUG start
|
||||
corechaindb -l DEBUG start
|
||||
fi
|
||||
|
@ -10,7 +10,7 @@ set -e -x
|
||||
if [[ -z ${TOXENV} ]]; then
|
||||
|
||||
if [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
|
||||
docker-compose up -d bigchaindb
|
||||
docker-compose up -d corechaindb
|
||||
else
|
||||
docker-compose up -d bdb
|
||||
fi
|
||||
|
@ -12,10 +12,10 @@ pip install --upgrade pip
|
||||
if [[ -n ${TOXENV} ]]; then
|
||||
pip install --upgrade tox
|
||||
elif [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
|
||||
docker-compose build --no-cache --build-arg abci_status=enable bigchaindb
|
||||
docker-compose build --no-cache --build-arg abci_status=enable corechaindb
|
||||
elif [[ $BIGCHAINDB_INTEGRATION_TEST == 'enable' ]]; then
|
||||
docker-compose build bigchaindb python-driver
|
||||
docker-compose build corechaindb python-driver
|
||||
else
|
||||
docker-compose build --no-cache bigchaindb
|
||||
docker-compose build --no-cache corechaindb
|
||||
pip install --upgrade codecov
|
||||
fi
|
||||
|
@ -10,9 +10,9 @@ set -e -x
|
||||
if [[ -n ${TOXENV} ]]; then
|
||||
tox -e ${TOXENV}
|
||||
elif [[ ${BIGCHAINDB_CI_ABCI} == 'enable' ]]; then
|
||||
docker-compose exec bigchaindb pytest -v -m abci
|
||||
docker-compose exec corechaindb pytest -v -m abci
|
||||
elif [[ ${BIGCHAINDB_ACCEPTANCE_TEST} == 'enable' ]]; then
|
||||
./run-acceptance-test.sh
|
||||
else
|
||||
docker-compose exec bigchaindb pytest -v --cov=bigchaindb --cov-report xml:htmlcov/coverage.xml
|
||||
docker-compose exec corechaindb pytest -v --cov=corechaindb --cov-report xml:htmlcov/coverage.xml
|
||||
fi
|
||||
|
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@ -9,6 +9,6 @@ Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
There are many ways you can contribute to the BigchainDB project, some very easy and others more involved.
|
||||
|
||||
All of that is documented elsewhere: go to the "[Contributing to BigchainDB" docs on ReadTheDocs](https://docs.bigchaindb.com/projects/contributing/en/latest/index.html).
|
||||
All of that is documented elsewhere: go to the "[Contributing to BigchainDB" docs on ReadTheDocs](https://docs.corechaindb.com/projects/contributing/en/latest/index.html).
|
||||
|
||||
Note: GitHub automatically links to this file (`.github/CONTRIBUTING.md`) when a contributor creates a new issue or pull request, so you shouldn't delete it. Just use it to point people to full and proper help elsewhere.
|
||||
|
6
.github/ISSUE_TEMPLATE.md
vendored
6
.github/ISSUE_TEMPLATE.md
vendored
@ -1,9 +1,9 @@
|
||||
# Do you want to:
|
||||
|
||||
- make a bug report? Then read below about what should go in a bug report.
|
||||
- make a feature request or proposal? Then read [the page about how to make a feature request or proposal](https://docs.bigchaindb.com/projects/contributing/en/latest/ways-can-contribute/make-a-feature-request-or-proposal.html).
|
||||
- ask a question about BigchainDB? Then [go to Gitter](https://gitter.im/bigchaindb/bigchaindb) (our chat room) and ask it there.
|
||||
- share your neat idea or realization? Then [go to Gitter](https://gitter.im/bigchaindb/bigchaindb) (our chat room) and share it there.
|
||||
- make a feature request or proposal? Then read [the page about how to make a feature request or proposal](https://docs.corechaindb.com/projects/contributing/en/latest/ways-can-contribute/make-a-feature-request-or-proposal.html).
|
||||
- ask a question about BigchainDB? Then [go to Gitter](https://gitter.im/corechaindb/corechaindb) (our chat room) and ask it there.
|
||||
- share your neat idea or realization? Then [go to Gitter](https://gitter.im/corechaindb/corechaindb) (our chat room) and share it there.
|
||||
|
||||
# What Should Go in a Bug Report
|
||||
|
||||
|
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -15,4 +15,4 @@ Resolves #MMMM
|
||||
|
||||
## BEPs Implemented
|
||||
|
||||
What [BEPs](https://github.com/bigchaindb/beps) does this pull request implement, if any?
|
||||
What [BEPs](https://github.com/corechaindb/beps) does this pull request implement, if any?
|
||||
|
@ -21,5 +21,5 @@ repos:
|
||||
# list of error codes to check, see: http://www.pydocstyle.org/en/latest/error_codes.html
|
||||
args: ['--select=D204,D201,D209,D210,D212,D300,D403']
|
||||
|
||||
# negate the exclude to only apply the hooks to 'bigchaindb' and 'tests' folder
|
||||
exclude: '^(?!bigchaindb/)(?!tests/)(?!acceptance/)'
|
||||
# negate the exclude to only apply the hooks to 'corechaindb' and 'tests' folder
|
||||
exclude: '^(?!corechaindb/)(?!tests/)(?!acceptance/)'
|
||||
|
920
CHANGELOG.md
920
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@ -42,7 +42,7 @@ This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior directed at yourself or another community member may be
|
||||
reported by contacting a project maintainer at [contact@bigchaindb.com](mailto:contact@bigchaindb.com). All
|
||||
reported by contacting a project maintainer at [contact@corechaindb.com](mailto:contact@corechaindb.com). All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is appropriate to the circumstances. Maintainers are
|
||||
obligated to maintain confidentiality with regard to the reporter of an
|
||||
|
@ -13,12 +13,12 @@ RUN apt-get -qq update \
|
||||
VOLUME ["/data", "/certs"]
|
||||
|
||||
ENV PYTHONUNBUFFERED 0
|
||||
ENV BIGCHAINDB_CONFIG_PATH /data/.bigchaindb
|
||||
ENV BIGCHAINDB_CONFIG_PATH /data/.corechaindb
|
||||
ENV BIGCHAINDB_SERVER_BIND 0.0.0.0:9984
|
||||
ENV BIGCHAINDB_WSSERVER_HOST 0.0.0.0
|
||||
ENV BIGCHAINDB_WSSERVER_SCHEME ws
|
||||
ENV BIGCHAINDB_WSSERVER_ADVERTISED_HOST 0.0.0.0
|
||||
ENV BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME ws
|
||||
ENV BIGCHAINDB_WSSERVER_ADVERTISED_PORT 9985
|
||||
ENTRYPOINT ["bigchaindb"]
|
||||
ENTRYPOINT ["corechaindb"]
|
||||
CMD ["start"]
|
||||
|
@ -27,4 +27,4 @@ ENV BIGCHAINDB_WSSERVER_ADVERTISED_SCHEME ws
|
||||
|
||||
ENV BIGCHAINDB_TENDERMINT_PORT 26657
|
||||
ARG backend
|
||||
RUN bigchaindb -y configure "$backend"
|
||||
RUN corechaindb -y configure "$backend"
|
@ -32,4 +32,4 @@ RUN mkdir -p /usr/src/app
|
||||
COPY . /usr/src/app/
|
||||
WORKDIR /usr/src/app
|
||||
RUN pip install -e .[dev]
|
||||
RUN bigchaindb -y configure
|
||||
RUN corechaindb -y configure
|
||||
|
@ -5,8 +5,8 @@
|
||||
For all the code and documentation in this repository, the copyright is owned by one or more of the following:
|
||||
|
||||
- BigchainDB GmbH
|
||||
- A BigchainDB contributor who agreed to a BigchainDB Contributor License Agreement (CLA) with BigchainDB GmbH. (See [BEP-16](https://github.com/bigchaindb/BEPs/tree/master/16).)
|
||||
- A BigchainDB contributor who signed off on the Developer Certificate of Origin (DCO) for all their contributions. (See [BEP-24](https://github.com/bigchaindb/BEPs/tree/master/24).)
|
||||
- A BigchainDB contributor who agreed to a BigchainDB Contributor License Agreement (CLA) with BigchainDB GmbH. (See [BEP-16](https://github.com/corechaindb/BEPs/tree/master/16).)
|
||||
- A BigchainDB contributor who signed off on the Developer Certificate of Origin (DCO) for all their contributions. (See [BEP-24](https://github.com/corechaindb/BEPs/tree/master/24).)
|
||||
- (Rarely, see the **Exceptions Section** below) A third pary who licensed the code in question under an open source license.
|
||||
|
||||
## Code Licenses
|
||||
|
14
Makefile
14
Makefile
@ -56,34 +56,34 @@ help: ## Show this help
|
||||
@$(HELP) < $(MAKEFILE_LIST)
|
||||
|
||||
run: check-deps ## Run BigchainDB from source (stop it with ctrl+c)
|
||||
# although bigchaindb has tendermint and mongodb in depends_on,
|
||||
# although corechaindb has tendermint and mongodb in depends_on,
|
||||
# launch them first otherwise tendermint will get stuck upon sending yet another log
|
||||
# due to some docker-compose issue; does not happen when containers are run as daemons
|
||||
@$(DC) up --no-deps mongodb tendermint bigchaindb
|
||||
@$(DC) up --no-deps mongodb tendermint corechaindb
|
||||
|
||||
start: check-deps ## Run BigchainDB from source and daemonize it (stop with `make stop`)
|
||||
@$(DC) up -d bigchaindb
|
||||
@$(DC) up -d corechaindb
|
||||
|
||||
stop: check-deps ## Stop BigchainDB
|
||||
@$(DC) stop
|
||||
|
||||
logs: check-deps ## Attach to the logs
|
||||
@$(DC) logs -f bigchaindb
|
||||
@$(DC) logs -f corechaindb
|
||||
|
||||
test: check-deps test-unit test-acceptance ## Run unit and acceptance tests
|
||||
|
||||
test-unit: check-deps ## Run all tests once
|
||||
@$(DC) up -d bdb
|
||||
@$(DC) exec bigchaindb pytest
|
||||
@$(DC) exec corechaindb pytest
|
||||
|
||||
test-unit-watch: check-deps ## Run all tests and wait. Every time you change code, tests will be run again
|
||||
@$(DC) run --rm --no-deps bigchaindb pytest -f
|
||||
@$(DC) run --rm --no-deps corechaindb pytest -f
|
||||
|
||||
test-acceptance: check-deps ## Run all acceptance tests
|
||||
@./run-acceptance-test.sh
|
||||
|
||||
cov: check-deps ## Check code coverage and open the result in the browser
|
||||
@$(DC) run --rm bigchaindb pytest -v --cov=bigchaindb --cov-report html
|
||||
@$(DC) run --rm corechaindb pytest -v --cov=corechaindb --cov-report html
|
||||
$(BROWSER) htmlcov/index.html
|
||||
|
||||
doc: check-deps ## Generate HTML documentation and open it in the browser
|
||||
|
@ -16,7 +16,7 @@ Our starting point is [PEP8](https://www.python.org/dev/peps/pep-0008/), the sta
|
||||
BigchainDB uses Python 3.5+, so you can ignore all PEP8 guidelines specific to Python 2.
|
||||
|
||||
We use [pre-commit](http://pre-commit.com/) to check some of the rules below before every commit but not everything is realized yet.
|
||||
The hooks we use can be found in the [.pre-commit-config.yaml](https://github.com/bigchaindb/bigchaindb/blob/master/.pre-commit-config.yaml) file.
|
||||
The hooks we use can be found in the [.pre-commit-config.yaml](https://github.com/corechaindb/corechaindb/blob/master/.pre-commit-config.yaml) file.
|
||||
|
||||
### Python Docstrings
|
||||
|
||||
@ -86,12 +86,12 @@ we use the `format()` version. The [official Python documentation says](https://
|
||||
|
||||
We use [Flake8](http://flake8.pycqa.org/en/latest/index.html) to check our Python code style. Once you have it installed, you can run it using:
|
||||
```text
|
||||
flake8 --max-line-length 119 bigchaindb/
|
||||
flake8 --max-line-length 119 corechaindb/
|
||||
```
|
||||
|
||||
|
||||
## Writing and Running (Python) Tests
|
||||
|
||||
The content of this section was moved to [`bigchaindb/tests/README.md`](https://github.com/bigchaindb/bigchaindb/blob/master/tests/README.md).
|
||||
The content of this section was moved to [`corechaindb/tests/README.md`](https://github.com/corechaindb/corechaindb/blob/master/tests/README.md).
|
||||
|
||||
Note: We automatically run all tests on all pull requests (using Travis CI), so you should definitely run all tests locally before you submit a pull request. See the above-linked README file for instructions.
|
||||
|
42
README.md
42
README.md
@ -10,12 +10,12 @@ Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
so show the latest GitHub release instead.
|
||||
--->
|
||||
|
||||
[](https://codecov.io/github/bigchaindb/bigchaindb?branch=master)
|
||||
[](https://github.com/bigchaindb/bigchaindb/releases)
|
||||
[](https://pypi.org/project/BigchainDB/)
|
||||
[](https://travis-ci.com/bigchaindb/bigchaindb)
|
||||
[](https://docs.bigchaindb.com/projects/server/en/latest/)
|
||||
[](https://gitter.im/bigchaindb/bigchaindb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://codecov.io/github/corechaindb/corechaindb?branch=master)
|
||||
[](https://github.com/corechaindb/corechaindb/releases)
|
||||
[](https://pypi.org/project/BigchainDB/)
|
||||
[](https://travis-ci.com/corechaindb/corechaindb)
|
||||
[](https://docs.corechaindb.com/projects/server/en/latest/)
|
||||
[](https://gitter.im/corechaindb/corechaindb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
# BigchainDB Server
|
||||
|
||||
@ -23,17 +23,17 @@ BigchainDB is the blockchain database. This repository is for _BigchainDB Server
|
||||
|
||||
## The Basics
|
||||
|
||||
* [Try the Quickstart](https://docs.bigchaindb.com/projects/server/en/latest/quickstart.html)
|
||||
* [Read the BigchainDB 2.0 whitepaper](https://www.bigchaindb.com/whitepaper/)
|
||||
* [Check out the _Hitchiker's Guide to BigchainDB_](https://www.bigchaindb.com/developers/guide/)
|
||||
* [Try the Quickstart](https://docs.corechaindb.com/projects/server/en/latest/quickstart.html)
|
||||
* [Read the BigchainDB 2.0 whitepaper](https://www.corechaindb.com/whitepaper/)
|
||||
* [Check out the _Hitchiker's Guide to BigchainDB_](https://www.corechaindb.com/developers/guide/)
|
||||
|
||||
## Run and Test BigchainDB Server from the `master` Branch
|
||||
|
||||
Running and testing the latest version of BigchainDB Server is easy. Make sure you have a recent version of [Docker Compose](https://docs.docker.com/compose/install/) installed. When you are ready, fire up a terminal and run:
|
||||
|
||||
```text
|
||||
git clone https://github.com/bigchaindb/bigchaindb.git
|
||||
cd bigchaindb
|
||||
git clone https://github.com/corechaindb/corechaindb.git
|
||||
cd corechaindb
|
||||
make run
|
||||
```
|
||||
|
||||
@ -55,23 +55,23 @@ To view all commands available, run `make`.
|
||||
|
||||
## Links for Everyone
|
||||
|
||||
* [BigchainDB.com](https://www.bigchaindb.com/) - the main BigchainDB website, including newsletter signup
|
||||
* [Roadmap](https://github.com/bigchaindb/org/blob/master/ROADMAP.md)
|
||||
* [Blog](https://medium.com/the-bigchaindb-blog)
|
||||
* [BigchainDB.com](https://www.corechaindb.com/) - the main BigchainDB website, including newsletter signup
|
||||
* [Roadmap](https://github.com/corechaindb/org/blob/master/ROADMAP.md)
|
||||
* [Blog](https://medium.com/the-corechaindb-blog)
|
||||
* [Twitter](https://twitter.com/BigchainDB)
|
||||
|
||||
## Links for Developers
|
||||
|
||||
* [All BigchainDB Documentation](https://docs.bigchaindb.com/en/latest/)
|
||||
* [BigchainDB Server Documentation](https://docs.bigchaindb.com/projects/server/en/latest/index.html)
|
||||
* [All BigchainDB Documentation](https://docs.corechaindb.com/en/latest/)
|
||||
* [BigchainDB Server Documentation](https://docs.corechaindb.com/projects/server/en/latest/index.html)
|
||||
* [CONTRIBUTING.md](.github/CONTRIBUTING.md) - how to contribute
|
||||
* [Community guidelines](CODE_OF_CONDUCT.md)
|
||||
* [Open issues](https://github.com/bigchaindb/bigchaindb/issues)
|
||||
* [Open pull requests](https://github.com/bigchaindb/bigchaindb/pulls)
|
||||
* [Gitter chatroom](https://gitter.im/bigchaindb/bigchaindb)
|
||||
* [Open issues](https://github.com/corechaindb/corechaindb/issues)
|
||||
* [Open pull requests](https://github.com/corechaindb/corechaindb/pulls)
|
||||
* [Gitter chatroom](https://gitter.im/corechaindb/corechaindb)
|
||||
|
||||
## Legal
|
||||
|
||||
* [Licenses](LICENSES.md) - open source & open content
|
||||
* [Imprint](https://www.bigchaindb.com/imprint/)
|
||||
* [Contact Us](https://www.bigchaindb.com/contact/)
|
||||
* [Imprint](https://www.corechaindb.com/imprint/)
|
||||
* [Contact Us](https://www.corechaindb.com/contact/)
|
||||
|
42
README_cn.md
42
README_cn.md
@ -10,12 +10,12 @@ Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
so show the latest GitHub release instead.
|
||||
--->
|
||||
|
||||
[](https://codecov.io/github/bigchaindb/bigchaindb?branch=master)
|
||||
[](https://github.com/bigchaindb/bigchaindb/releases)
|
||||
[](https://pypi.org/project/BigchainDB/)
|
||||
[](https://travis-ci.com/bigchaindb/bigchaindb)
|
||||
[](https://docs.bigchaindb.com/projects/server/en/latest/)
|
||||
[](https://gitter.im/bigchaindb/bigchaindb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://codecov.io/github/corechaindb/corechaindb?branch=master)
|
||||
[](https://github.com/corechaindb/corechaindb/releases)
|
||||
[](https://pypi.org/project/BigchainDB/)
|
||||
[](https://travis-ci.com/corechaindb/corechaindb)
|
||||
[](https://docs.corechaindb.com/projects/server/en/latest/)
|
||||
[](https://gitter.im/corechaindb/corechaindb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
# BigchainDB 服务器
|
||||
|
||||
@ -23,17 +23,17 @@ BigchainDB 是区块链数据库. 这是 _BigchainDB 服务器_ 的仓库.
|
||||
|
||||
## 基础知识
|
||||
|
||||
* [尝试快速开始](https://docs.bigchaindb.com/projects/server/en/latest/quickstart.html)
|
||||
* [阅读 BigchainDB 2.0 白皮书](https://www.bigchaindb.com/whitepaper/)
|
||||
* [查阅漫游指南](https://www.bigchaindb.com/developers/guide/)
|
||||
* [尝试快速开始](https://docs.corechaindb.com/projects/server/en/latest/quickstart.html)
|
||||
* [阅读 BigchainDB 2.0 白皮书](https://www.corechaindb.com/whitepaper/)
|
||||
* [查阅漫游指南](https://www.corechaindb.com/developers/guide/)
|
||||
|
||||
## 运行和测试 `master` 分支的 BigchainDB 服务器
|
||||
|
||||
运行和测试最新版本的 BigchainDB 服务器非常简单. 确认你有安装最新版本的 [Docker Compose](https://docs.docker.com/compose/install/). 当你准备好了, 打开一个终端并运行:
|
||||
|
||||
```text
|
||||
git clone https://github.com/bigchaindb/bigchaindb.git
|
||||
cd bigchaindb
|
||||
git clone https://github.com/corechaindb/corechaindb.git
|
||||
cd corechaindb
|
||||
make run
|
||||
```
|
||||
|
||||
@ -55,23 +55,23 @@ BigchainDB 应该可以通过 `http://localhost:9984/` 访问.
|
||||
|
||||
## 一般人员链接
|
||||
|
||||
* [BigchainDB.com](https://www.bigchaindb.com/) - BigchainDB 主网站, 包括新闻订阅
|
||||
* [路线图](https://github.com/bigchaindb/org/blob/master/ROADMAP.md)
|
||||
* [博客](https://medium.com/the-bigchaindb-blog)
|
||||
* [BigchainDB.com](https://www.corechaindb.com/) - BigchainDB 主网站, 包括新闻订阅
|
||||
* [路线图](https://github.com/corechaindb/org/blob/master/ROADMAP.md)
|
||||
* [博客](https://medium.com/the-corechaindb-blog)
|
||||
* [推特](https://twitter.com/BigchainDB)
|
||||
|
||||
## 开发人员链接
|
||||
|
||||
* [所有的 BigchainDB 文档](https://docs.bigchaindb.com/en/latest/)
|
||||
* [BigchainDB 服务器 文档](https://docs.bigchaindb.com/projects/server/en/latest/index.html)
|
||||
* [所有的 BigchainDB 文档](https://docs.corechaindb.com/en/latest/)
|
||||
* [BigchainDB 服务器 文档](https://docs.corechaindb.com/projects/server/en/latest/index.html)
|
||||
* [CONTRIBUTING.md](.github/CONTRIBUTING.md) - how to contribute
|
||||
* [社区指南](CODE_OF_CONDUCT.md)
|
||||
* [公开问题](https://github.com/bigchaindb/bigchaindb/issues)
|
||||
* [公开的 pull request](https://github.com/bigchaindb/bigchaindb/pulls)
|
||||
* [Gitter 聊天室](https://gitter.im/bigchaindb/bigchaindb)
|
||||
* [公开问题](https://github.com/corechaindb/corechaindb/issues)
|
||||
* [公开的 pull request](https://github.com/corechaindb/corechaindb/pulls)
|
||||
* [Gitter 聊天室](https://gitter.im/corechaindb/corechaindb)
|
||||
|
||||
## 法律声明
|
||||
|
||||
* [许可](LICENSES.md) - 开源代码 & 开源内容
|
||||
* [印记](https://www.bigchaindb.com/imprint/)
|
||||
* [联系我们](https://www.bigchaindb.com/contact/)
|
||||
* [印记](https://www.corechaindb.com/imprint/)
|
||||
* [联系我们](https://www.corechaindb.com/contact/)
|
||||
|
@ -1,9 +1,9 @@
|
||||
[](https://codecov.io/github/bigchaindb/bigchaindb?branch=master)
|
||||
[](https://github.com/bigchaindb/bigchaindb/releases)
|
||||
[](https://pypi.org/project/BigchainDB/)
|
||||
[](https://travis-ci.org/bigchaindb/bigchaindb)
|
||||
[](https://docs.bigchaindb.com/projects/server/en/latest/)
|
||||
[](https://gitter.im/bigchaindb/bigchaindb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://codecov.io/github/corechaindb/corechaindb?branch=master)
|
||||
[](https://github.com/corechaindb/corechaindb/releases)
|
||||
[](https://pypi.org/project/BigchainDB/)
|
||||
[](https://travis-ci.org/corechaindb/corechaindb)
|
||||
[](https://docs.corechaindb.com/projects/server/en/latest/)
|
||||
[](https://gitter.im/corechaindb/corechaindb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
# BigchainDB 서버
|
||||
|
||||
@ -11,17 +11,17 @@ BigchaingDB는 블록체인 데이터베이스입니다. 이 저장소는 _Bigch
|
||||
|
||||
### 기본 사항
|
||||
|
||||
* [빠른 시작 사용해보기](https://docs.bigchaindb.com/projects/server/en/latest/quickstart.html)
|
||||
* [BigchainDB 2.0 백서 읽기](https://www.bigchaindb.com/whitepaper/)
|
||||
* [BigchainDB에 대한 _Hitchiker's Guide_를 확인십시오.](https://www.bigchaindb.com/developers/guide/)
|
||||
* [빠른 시작 사용해보기](https://docs.corechaindb.com/projects/server/en/latest/quickstart.html)
|
||||
* [BigchainDB 2.0 백서 읽기](https://www.corechaindb.com/whitepaper/)
|
||||
* [BigchainDB에 대한 _Hitchiker's Guide_를 확인십시오.](https://www.corechaindb.com/developers/guide/)
|
||||
|
||||
### `master` Branch에서 BigchainDB 서버 실행 및 테스트
|
||||
|
||||
BigchaingDB 서버의 최신 버전을 실행하고 테스트하는 것은 어렵지 않습니다. [Docker Compose](https://docs.docker.com/compose/install/)의 최신 버전이 설치되어 있는지 확인하십시오. 준비가 되었다면, 터미널에서 다음을 실행하십시오.
|
||||
|
||||
```text
|
||||
git clone https://github.com/bigchaindb/bigchaindb.git
|
||||
cd bigchaindb
|
||||
git clone https://github.com/corechaindb/corechaindb.git
|
||||
cd corechaindb
|
||||
make run
|
||||
```
|
||||
|
||||
@ -43,23 +43,23 @@ make run
|
||||
|
||||
### 모두를 위한 링크들
|
||||
|
||||
* [BigchainDB.com ](https://www.bigchaindb.com/)- 뉴스 레터 가입을 포함하는 BigchainDB 주요 웹 사이트
|
||||
* [로드맵](https://github.com/bigchaindb/org/blob/master/ROADMAP.md)
|
||||
* [블로그](https://medium.com/the-bigchaindb-blog)
|
||||
* [BigchainDB.com ](https://www.corechaindb.com/)- 뉴스 레터 가입을 포함하는 BigchainDB 주요 웹 사이트
|
||||
* [로드맵](https://github.com/corechaindb/org/blob/master/ROADMAP.md)
|
||||
* [블로그](https://medium.com/the-corechaindb-blog)
|
||||
* [트위터](https://twitter.com/BigchainDB)
|
||||
|
||||
### 개발자들을 위한 링크들
|
||||
|
||||
* [모든 BigchainDB 문서](https://docs.bigchaindb.com/en/latest/)
|
||||
* [BigchainDB 서버 문서](https://docs.bigchaindb.com/projects/server/en/latest/index.html)
|
||||
* [CONTRIBUTING.md](https://github.com/bigchaindb/bigchaindb/blob/master/.github/CONTRIBUTING.md) - 기여를 하는 방법
|
||||
* [커뮤니티 가이드라인](https://github.com/bigchaindb/bigchaindb/blob/master/CODE_OF_CONDUCT.md)
|
||||
* [이슈 작성](https://github.com/bigchaindb/bigchaindb/issues)
|
||||
* [pull request 하기](https://github.com/bigchaindb/bigchaindb/pulls)
|
||||
* [Gitter 채팅방](https://gitter.im/bigchaindb/bigchaindb)
|
||||
* [모든 BigchainDB 문서](https://docs.corechaindb.com/en/latest/)
|
||||
* [BigchainDB 서버 문서](https://docs.corechaindb.com/projects/server/en/latest/index.html)
|
||||
* [CONTRIBUTING.md](https://github.com/corechaindb/corechaindb/blob/master/.github/CONTRIBUTING.md) - 기여를 하는 방법
|
||||
* [커뮤니티 가이드라인](https://github.com/corechaindb/corechaindb/blob/master/CODE_OF_CONDUCT.md)
|
||||
* [이슈 작성](https://github.com/corechaindb/corechaindb/issues)
|
||||
* [pull request 하기](https://github.com/corechaindb/corechaindb/pulls)
|
||||
* [Gitter 채팅방](https://gitter.im/corechaindb/corechaindb)
|
||||
|
||||
### 합법
|
||||
|
||||
* [라이선스](https://github.com/bigchaindb/bigchaindb/blob/master/LICENSES.md) - 오픈 소스 & 오픈 콘텐츠
|
||||
* [발행](https://www.bigchaindb.com/imprint/)
|
||||
* [연락처](https://www.bigchaindb.com/contact/)
|
||||
* [라이선스](https://github.com/corechaindb/corechaindb/blob/master/LICENSES.md) - 오픈 소스 & 오픈 콘텐츠
|
||||
* [발행](https://www.corechaindb.com/imprint/)
|
||||
* [연락처](https://www.corechaindb.com/contact/)
|
||||
|
@ -25,7 +25,7 @@ to [regular semantic versioning](http://semver.org/), but there's no hyphen, e.g
|
||||
|
||||
We use `0.9` and `0.9.0` as example version and short-version values below. You should replace those with the correct values for your new version.
|
||||
|
||||
We follow [BEP-1](https://github.com/bigchaindb/BEPs/tree/master/1), which is our variant of C4, the Collective Code Construction Contract, so a release is just a [tagged commit](https://git-scm.com/book/en/v2/Git-Basics-Tagging) on the `master` branch, i.e. a label for a particular Git commit.
|
||||
We follow [BEP-1](https://github.com/corechaindb/BEPs/tree/master/1), which is our variant of C4, the Collective Code Construction Contract, so a release is just a [tagged commit](https://git-scm.com/book/en/v2/Git-Basics-Tagging) on the `master` branch, i.e. a label for a particular Git commit.
|
||||
|
||||
The following steps are what we do to release a new version of _BigchainDB Server_. The steps to release the Python Driver are similar but not the same.
|
||||
|
||||
@ -37,13 +37,13 @@ The following steps are what we do to release a new version of _BigchainDB Serve
|
||||
- Update all Docker image tags in all Kubernetes YAML files (in the `k8s/` directory).
|
||||
For example, in the files:
|
||||
|
||||
- `k8s/bigchaindb/bigchaindb-ss.yaml` and
|
||||
- `k8s/dev-setup/bigchaindb.yaml`
|
||||
- `k8s/corechaindb/corechaindb-ss.yaml` and
|
||||
- `k8s/dev-setup/corechaindb.yaml`
|
||||
|
||||
find the line of the form `image: bigchaindb/bigchaindb:0.8.1` and change the version number to the new version number, e.g. `0.9.0`. (This is the Docker image that Kubernetes should pull from Docker Hub.)
|
||||
find the line of the form `image: corechaindb/corechaindb:0.8.1` and change the version number to the new version number, e.g. `0.9.0`. (This is the Docker image that Kubernetes should pull from Docker Hub.)
|
||||
Keep in mind that this is a _Docker image tag_ so our naming convention is
|
||||
a bit different; see Note 2 in the **Notes** section above.
|
||||
- In `bigchaindb/version.py`:
|
||||
- In `corechaindb/version.py`:
|
||||
- update `__version__` to e.g. `0.9.0` (with no `.dev` on the end)
|
||||
- update `__short_version__` to e.g. `0.9` (with no `.dev` on the end)
|
||||
- In the docs about installing BigchainDB (and Tendermint), and in the associated scripts, recommend/install a version of Tendermint that _actually works_ with the soon-to-be-released version of BigchainDB. You can find all such references by doing a search for the previously-recommended version number, such as `0.31.5`.
|
||||
@ -51,7 +51,7 @@ The following steps are what we do to release a new version of _BigchainDB Serve
|
||||
|
||||
2. **Wait for all the tests to pass!**
|
||||
3. Merge the pull request into the `master` branch.
|
||||
4. Go to the [bigchaindb/bigchaindb Releases page on GitHub](https://github.com/bigchaindb/bigchaindb/releases)
|
||||
4. Go to the [corechaindb/corechaindb Releases page on GitHub](https://github.com/corechaindb/corechaindb/releases)
|
||||
and click the "Draft a new release" button.
|
||||
5. Fill in the details:
|
||||
- **Tag version:** version number preceded by `v`, e.g. `v0.9.1`
|
||||
@ -59,9 +59,9 @@ The following steps are what we do to release a new version of _BigchainDB Serve
|
||||
- **Title:** Same as tag version above, e.g `v0.9.1`
|
||||
- **Description:** The body of the changelog entry (Added, Changed, etc.)
|
||||
6. Click "Publish release" to publish the release on GitHub.
|
||||
7. On your local computer, make sure you're on the `master` branch and that it's up-to-date with the `master` branch in the bigchaindb/bigchaindb repository (e.g. `git pull upstream master`). We're going to use that to push a new `bigchaindb` package to PyPI.
|
||||
7. On your local computer, make sure you're on the `master` branch and that it's up-to-date with the `master` branch in the corechaindb/corechaindb repository (e.g. `git pull upstream master`). We're going to use that to push a new `corechaindb` package to PyPI.
|
||||
8. Make sure you have a `~/.pypirc` file containing credentials for PyPI.
|
||||
9. Do `make release` to build and publish the new `bigchaindb` package on PyPI. For this step you need to have `twine` installed. If you get an error like `Makefile:135: recipe for target 'clean-pyc' failed` then try doing
|
||||
9. Do `make release` to build and publish the new `corechaindb` package on PyPI. For this step you need to have `twine` installed. If you get an error like `Makefile:135: recipe for target 'clean-pyc' failed` then try doing
|
||||
```text
|
||||
sudo chown -R $(whoami):$(whoami) .
|
||||
```
|
||||
@ -80,8 +80,8 @@ The following steps are what we do to release a new version of _BigchainDB Serve
|
||||
3. Scroll to the bottom of the page and click "Save".
|
||||
11. Go to [Docker Hub](https://hub.docker.com/) and sign in, then:
|
||||
- Click on "Organizations"
|
||||
- Click on "bigchaindb"
|
||||
- Click on "bigchaindb/bigchaindb"
|
||||
- Click on "corechaindb"
|
||||
- Click on "corechaindb/corechaindb"
|
||||
- Click on "Build Settings"
|
||||
- Find the row where "Docker Tag Name" equals `latest`
|
||||
and change the value of "Name" to the name (Git tag)
|
||||
|
@ -7,8 +7,8 @@ Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
# BigchainDB Roadmap
|
||||
|
||||
We moved the BigchainDB Roadmap to the bigchaindb/org repository; see:
|
||||
We moved the BigchainDB Roadmap to the corechaindb/org repository; see:
|
||||
|
||||
[https://github.com/bigchaindb/org/blob/master/ROADMAP.md](https://github.com/bigchaindb/org/blob/master/ROADMAP.md)
|
||||
[https://github.com/corechaindb/org/blob/master/ROADMAP.md](https://github.com/corechaindb/org/blob/master/ROADMAP.md)
|
||||
|
||||
(We kept this file here to avoid breaking some links.)
|
||||
|
@ -5,5 +5,5 @@ RUN pip install --upgrade \
|
||||
pycco \
|
||||
websocket-client~=0.47.0 \
|
||||
pytest~=3.0 \
|
||||
bigchaindb-driver~=0.6.2 \
|
||||
corechaindb-driver~=0.6.2 \
|
||||
blns
|
||||
|
@ -16,7 +16,7 @@
|
||||
# the remote system, and also checking the `outputs` of a given public key.
|
||||
#
|
||||
# This acceptance test is a rip-off of our
|
||||
# [tutorial](https://docs.bigchaindb.com/projects/py-driver/en/latest/usage.html).
|
||||
# [tutorial](https://docs.corechaindb.com/projects/py-driver/en/latest/usage.html).
|
||||
|
||||
# ## Imports
|
||||
# We need some utils from the `os` package, we will interact with
|
||||
@ -24,8 +24,8 @@
|
||||
import os
|
||||
|
||||
# For this test case we import and use the Python Driver.
|
||||
from bigchaindb_driver import BigchainDB
|
||||
from bigchaindb_driver.crypto import generate_keypair
|
||||
from corechaindb_driver import BigchainDB
|
||||
from corechaindb_driver.crypto import generate_keypair
|
||||
|
||||
|
||||
def test_basic():
|
||||
|
@ -17,7 +17,7 @@
|
||||
# of a given transaction.
|
||||
#
|
||||
# This integration test is a rip-off of our
|
||||
# [tutorial](https://docs.bigchaindb.com/projects/py-driver/en/latest/usage.html).
|
||||
# [tutorial](https://docs.corechaindb.com/projects/py-driver/en/latest/usage.html).
|
||||
|
||||
# ## Imports
|
||||
# We need some utils from the `os` package, we will interact with
|
||||
@ -26,11 +26,11 @@
|
||||
# And of course, we also need the `BadRequest`.
|
||||
import os
|
||||
import pytest
|
||||
from bigchaindb_driver.exceptions import BadRequest
|
||||
from corechaindb_driver.exceptions import BadRequest
|
||||
|
||||
# For this test case we import and use the Python Driver.
|
||||
from bigchaindb_driver import BigchainDB
|
||||
from bigchaindb_driver.crypto import generate_keypair
|
||||
from corechaindb_driver import BigchainDB
|
||||
from corechaindb_driver.crypto import generate_keypair
|
||||
|
||||
|
||||
def test_divisible_assets():
|
||||
|
@ -11,9 +11,9 @@ from uuid import uuid4
|
||||
from threading import Thread
|
||||
import queue
|
||||
|
||||
import bigchaindb_driver.exceptions
|
||||
from bigchaindb_driver import BigchainDB
|
||||
from bigchaindb_driver.crypto import generate_keypair
|
||||
import corechaindb_driver.exceptions
|
||||
from corechaindb_driver import BigchainDB
|
||||
from corechaindb_driver.crypto import generate_keypair
|
||||
|
||||
|
||||
def test_double_create():
|
||||
@ -33,7 +33,7 @@ def test_double_create():
|
||||
try:
|
||||
bdb.transactions.send_commit(tx)
|
||||
results.put('OK')
|
||||
except bigchaindb_driver.exceptions.TransportError as e:
|
||||
except corechaindb_driver.exceptions.TransportError as e:
|
||||
results.put('FAIL')
|
||||
|
||||
t1 = Thread(target=send_and_queue, args=(tx, ))
|
||||
|
@ -17,7 +17,7 @@
|
||||
# of a given transaction.
|
||||
#
|
||||
# This integration test is a rip-off of our
|
||||
# [tutorial](https://docs.bigchaindb.com/projects/py-driver/en/latest/usage.html).
|
||||
# [tutorial](https://docs.corechaindb.com/projects/py-driver/en/latest/usage.html).
|
||||
|
||||
# ## Imports
|
||||
# We need some utils from the `os` package, we will interact with
|
||||
@ -25,8 +25,8 @@
|
||||
import os
|
||||
|
||||
# For this test case we import and use the Python Driver.
|
||||
from bigchaindb_driver import BigchainDB
|
||||
from bigchaindb_driver.crypto import generate_keypair
|
||||
from corechaindb_driver import BigchainDB
|
||||
from corechaindb_driver.crypto import generate_keypair
|
||||
|
||||
|
||||
def test_multiple_owners():
|
||||
|
@ -24,9 +24,9 @@ from blns import blns
|
||||
import pytest
|
||||
|
||||
# For this test case we import and use the Python Driver.
|
||||
from bigchaindb_driver import BigchainDB
|
||||
from bigchaindb_driver.crypto import generate_keypair
|
||||
from bigchaindb_driver.exceptions import BadRequest
|
||||
from corechaindb_driver import BigchainDB
|
||||
from corechaindb_driver.crypto import generate_keypair
|
||||
from corechaindb_driver.exceptions import BadRequest
|
||||
|
||||
naughty_strings = blns.all()
|
||||
|
||||
|
@ -27,8 +27,8 @@ from uuid import uuid4
|
||||
# [websocket](https://github.com/websocket-client/websocket-client) module
|
||||
from websocket import create_connection
|
||||
|
||||
from bigchaindb_driver import BigchainDB
|
||||
from bigchaindb_driver.crypto import generate_keypair
|
||||
from corechaindb_driver import BigchainDB
|
||||
from corechaindb_driver.crypto import generate_keypair
|
||||
|
||||
|
||||
def test_stream():
|
||||
|
@ -25,7 +25,7 @@ coverage:
|
||||
ignore: # files and folders that will be removed during processing
|
||||
- "docs/*"
|
||||
- "tests/*"
|
||||
- "bigchaindb/version.py"
|
||||
- "corechaindb/version.py"
|
||||
- "k8s/*"
|
||||
|
||||
comment:
|
||||
|
@ -17,7 +17,7 @@ The `BigchainDB` class is defined here. Most node-level operations and database
|
||||
|
||||
### [`models.py`](./models.py)
|
||||
|
||||
`Block`, `Transaction`, and `Asset` classes are defined here. The classes mirror the block and transaction structure from the [documentation](https://docs.bigchaindb.com/projects/server/en/latest/data-models/index.html), but also include methods for validation and signing.
|
||||
`Block`, `Transaction`, and `Asset` classes are defined here. The classes mirror the block and transaction structure from the [documentation](https://docs.corechaindb.com/projects/server/en/latest/data-models/index.html), but also include methods for validation and signing.
|
||||
|
||||
### [`validation.py`](./validation.py)
|
||||
|
||||
@ -35,7 +35,7 @@ Methods for managing the configuration, including loading configuration files, a
|
||||
|
||||
### [`commands`](./commands)
|
||||
|
||||
Contains code for the [CLI](https://docs.bigchaindb.com/projects/server/en/latest/server-reference/bigchaindb-cli.html) for BigchainDB.
|
||||
Contains code for the [CLI](https://docs.corechaindb.com/projects/server/en/latest/server-reference/corechaindb-cli.html) for BigchainDB.
|
||||
|
||||
### [`db`](./db)
|
||||
|
106
corechaindb/__init__.py
Normal file
106
corechaindb/__init__.py
Normal file
@ -0,0 +1,106 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import copy
|
||||
import logging
|
||||
|
||||
from corechaindb.log import DEFAULT_LOGGING_CONFIG as log_config
|
||||
from corechaindb.lib import BigchainDB # noqa
|
||||
from corechaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from corechaindb.version import __version__ # noqa
|
||||
from corechaindb.core import App # noqa
|
||||
|
||||
# from functools import reduce
|
||||
# PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16
|
||||
# basically, the port number is 9984
|
||||
|
||||
# The following variable is used by `corechaindb configure` to
|
||||
# prompt the user for database values. We cannot rely on
|
||||
# _base_database_localmongodb.keys() because dicts are unordered.
|
||||
# I tried to configure
|
||||
|
||||
_database_keys_map = {
|
||||
'localmongodb': ('host', 'port', 'name'),
|
||||
}
|
||||
|
||||
_base_database_localmongodb = {
|
||||
'host': 'localhost',
|
||||
'port': 27017,
|
||||
'name': 'bigchain',
|
||||
'replicaset': None,
|
||||
'login': None,
|
||||
'password': None,
|
||||
}
|
||||
|
||||
_database_localmongodb = {
|
||||
'backend': 'localmongodb',
|
||||
'connection_timeout': 5000,
|
||||
'max_tries': 3,
|
||||
'ssl': False,
|
||||
'ca_cert': None,
|
||||
'certfile': None,
|
||||
'keyfile': None,
|
||||
'keyfile_passphrase': None,
|
||||
'crlfile': None,
|
||||
}
|
||||
_database_localmongodb.update(_base_database_localmongodb)
|
||||
|
||||
_database_map = {
|
||||
'localmongodb': _database_localmongodb,
|
||||
}
|
||||
|
||||
config = {
|
||||
'server': {
|
||||
# Note: this section supports all the Gunicorn settings:
|
||||
# - http://docs.gunicorn.org/en/stable/settings.html
|
||||
'bind': 'localhost:9984',
|
||||
'loglevel': logging.getLevelName(
|
||||
log_config['handlers']['console']['level']).lower(),
|
||||
'workers': None, # if None, the value will be cpu_count * 2 + 1
|
||||
},
|
||||
'wsserver': {
|
||||
'scheme': 'ws',
|
||||
'host': 'localhost',
|
||||
'port': 9985,
|
||||
'advertised_scheme': 'ws',
|
||||
'advertised_host': 'localhost',
|
||||
'advertised_port': 9985,
|
||||
},
|
||||
'tendermint': {
|
||||
'host': 'localhost',
|
||||
'port': 26657,
|
||||
'version': 'v0.31.5', # look for __tm_supported_versions__
|
||||
},
|
||||
# FIXME: hardcoding to localmongodb for now
|
||||
'database': _database_map['localmongodb'],
|
||||
'log': {
|
||||
'file': log_config['handlers']['file']['filename'],
|
||||
'error_file': log_config['handlers']['errors']['filename'],
|
||||
'level_console': logging.getLevelName(
|
||||
log_config['handlers']['console']['level']).lower(),
|
||||
'level_logfile': logging.getLevelName(
|
||||
log_config['handlers']['file']['level']).lower(),
|
||||
'datefmt_console': log_config['formatters']['console']['datefmt'],
|
||||
'datefmt_logfile': log_config['formatters']['file']['datefmt'],
|
||||
'fmt_console': log_config['formatters']['console']['format'],
|
||||
'fmt_logfile': log_config['formatters']['file']['format'],
|
||||
'granular_levels': {},
|
||||
},
|
||||
}
|
||||
|
||||
# We need to maintain a backup copy of the original config dict in case
|
||||
# the user wants to reconfigure the node. Check ``corechaindb.config_utils``
|
||||
# for more info.
|
||||
_config = copy.deepcopy(config)
|
||||
from corechaindb.common.transaction import Transaction # noqa
|
||||
from corechaindb import models # noqa
|
||||
from corechaindb.upsert_validator import ValidatorElection # noqa
|
||||
from corechaindb.elections.vote import Vote # noqa
|
||||
|
||||
Transaction.register_type(Transaction.CREATE, models.Transaction)
|
||||
Transaction.register_type(Transaction.TRANSFER, models.Transaction)
|
||||
Transaction.register_type(ValidatorElection.OPERATION, ValidatorElection)
|
||||
Transaction.register_type(ChainMigrationElection.OPERATION, ChainMigrationElection)
|
||||
Transaction.register_type(Vote.OPERATION, Vote)
|
@ -27,17 +27,17 @@ generic functions based on certain conditions being met (e.g. the database backe
|
||||
To see what this looks like in BigchainDB, first note that our backend interfaces have been
|
||||
configured to dispatch based on a backend's **connection type**.
|
||||
|
||||
Call `bigchaindb.backend.connect()` to create an instance of a `Connection`:
|
||||
Call `corechaindb.backend.connect()` to create an instance of a `Connection`:
|
||||
|
||||
```python
|
||||
from bigchaindb.backend import connect
|
||||
from corechaindb.backend import connect
|
||||
connection = connect() # By default, uses the current configuration for backend, host, port, etc.
|
||||
```
|
||||
|
||||
Then, we can call a backend function by directly calling its interface:
|
||||
|
||||
```python
|
||||
from bigchaindb.backend import query
|
||||
from corechaindb.backend import query
|
||||
query.write_transaction(connection, ...)
|
||||
```
|
||||
|
||||
@ -46,6 +46,6 @@ Code can simply call the base interface function with a `Connection` instance, a
|
||||
will handle routing the call to the actual implementation.
|
||||
|
||||
BigchainDB will load and register the configured backend's implementation automatically (see
|
||||
`bigchaindb.backend.connect()`), so you should always just be able to call an interface function if
|
||||
`corechaindb.backend.connect()`), so you should always just be able to call an interface function if
|
||||
you have a `Connection` instance. A few helper utilities (see [`backend/utils.py`](./utils.py)) are
|
||||
also provided to make registering new backend implementations easier.
|
17
corechaindb/backend/__init__.py
Normal file
17
corechaindb/backend/__init__.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Generic backend database interfaces expected by BigchainDB.
|
||||
|
||||
The interfaces in this module allow BigchainDB to be agnostic about its
|
||||
database backend. One can configure BigchainDB to use different databases as
|
||||
its data store by setting the ``database.backend`` property in the
|
||||
configuration or the ``BIGCHAINDB_DATABASE_BACKEND`` environment variable.
|
||||
"""
|
||||
|
||||
# Include the backend interfaces
|
||||
from corechaindb.backend import schema, query # noqa
|
||||
|
||||
from corechaindb.backend.connection import connect # noqa
|
170
corechaindb/backend/connection.py
Normal file
170
corechaindb/backend/connection.py
Normal file
@ -0,0 +1,170 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import logging
|
||||
from importlib import import_module
|
||||
from itertools import repeat
|
||||
|
||||
import corechaindb
|
||||
from corechaindb.backend.exceptions import ConnectionError
|
||||
from corechaindb.backend.utils import get_corechaindb_config_value, get_corechaindb_config_value_or_key_error
|
||||
from corechaindb.common.exceptions import ConfigurationError
|
||||
|
||||
BACKENDS = {
|
||||
'localmongodb': 'corechaindb.backend.localmongodb.connection.LocalMongoDBConnection',
|
||||
}
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def connect(backend=None, host=None, port=None, name=None, max_tries=None,
|
||||
connection_timeout=None, replicaset=None, ssl=None, login=None, password=None,
|
||||
ca_cert=None, certfile=None, keyfile=None, keyfile_passphrase=None,
|
||||
crlfile=None):
|
||||
"""Create a new connection to the database backend.
|
||||
|
||||
All arguments default to the current configuration's values if not
|
||||
given.
|
||||
|
||||
Args:
|
||||
backend (str): the name of the backend to use.
|
||||
host (str): the host to connect to.
|
||||
port (int): the port to connect to.
|
||||
name (str): the name of the database to use.
|
||||
replicaset (str): the name of the replica set (only relevant for
|
||||
MongoDB connections).
|
||||
|
||||
Returns:
|
||||
An instance of :class:`~corechaindb.backend.connection.Connection`
|
||||
based on the given (or defaulted) :attr:`backend`.
|
||||
|
||||
Raises:
|
||||
:exc:`~ConnectionError`: If the connection to the database fails.
|
||||
:exc:`~ConfigurationError`: If the given (or defaulted) :attr:`backend`
|
||||
is not supported or could not be loaded.
|
||||
:exc:`~AuthenticationError`: If there is a OperationFailure due to
|
||||
Authentication failure after connecting to the database.
|
||||
"""
|
||||
|
||||
backend = backend or get_corechaindb_config_value_or_key_error('backend')
|
||||
host = host or get_corechaindb_config_value_or_key_error('host')
|
||||
port = port or get_corechaindb_config_value_or_key_error('port')
|
||||
dbname = name or get_corechaindb_config_value_or_key_error('name')
|
||||
# Not sure how to handle this here. This setting is only relevant for
|
||||
# mongodb.
|
||||
# I added **kwargs for both RethinkDBConnection and MongoDBConnection
|
||||
# to handle these these additional args. In case of RethinkDBConnection
|
||||
# it just does not do anything with it.
|
||||
#
|
||||
# UPD: RethinkDBConnection is not here anymore cause we no longer support RethinkDB.
|
||||
# The problem described above might be reconsidered next time we introduce a backend,
|
||||
# if it ever happens.
|
||||
replicaset = replicaset or get_corechaindb_config_value('replicaset')
|
||||
ssl = ssl if ssl is not None else get_corechaindb_config_value('ssl', False)
|
||||
login = login or get_corechaindb_config_value('login')
|
||||
password = password or get_corechaindb_config_value('password')
|
||||
ca_cert = ca_cert or get_corechaindb_config_value('ca_cert')
|
||||
certfile = certfile or get_corechaindb_config_value('certfile')
|
||||
keyfile = keyfile or get_corechaindb_config_value('keyfile')
|
||||
keyfile_passphrase = keyfile_passphrase or get_corechaindb_config_value('keyfile_passphrase', None)
|
||||
crlfile = crlfile or get_corechaindb_config_value('crlfile')
|
||||
|
||||
try:
|
||||
module_name, _, class_name = BACKENDS[backend].rpartition('.')
|
||||
Class = getattr(import_module(module_name), class_name)
|
||||
except KeyError:
|
||||
raise ConfigurationError('Backend `{}` is not supported. '
|
||||
'BigchainDB currently supports {}'.format(backend, BACKENDS.keys()))
|
||||
except (ImportError, AttributeError) as exc:
|
||||
raise ConfigurationError('Error loading backend `{}`'.format(backend)) from exc
|
||||
|
||||
logger.debug('Connection: {}'.format(Class))
|
||||
return Class(host=host, port=port, dbname=dbname,
|
||||
max_tries=max_tries, connection_timeout=connection_timeout,
|
||||
replicaset=replicaset, ssl=ssl, login=login, password=password,
|
||||
ca_cert=ca_cert, certfile=certfile, keyfile=keyfile,
|
||||
keyfile_passphrase=keyfile_passphrase, crlfile=crlfile)
|
||||
|
||||
|
||||
class Connection:
|
||||
"""Connection class interface.
|
||||
|
||||
All backend implementations should provide a connection class that inherits
|
||||
from and implements this class.
|
||||
"""
|
||||
|
||||
def __init__(self, host=None, port=None, dbname=None,
|
||||
connection_timeout=None, max_tries=None,
|
||||
**kwargs):
|
||||
"""Create a new :class:`~.Connection` instance.
|
||||
|
||||
Args:
|
||||
host (str): the host to connect to.
|
||||
port (int): the port to connect to.
|
||||
dbname (str): the name of the database to use.
|
||||
connection_timeout (int, optional): the milliseconds to wait
|
||||
until timing out the database connection attempt.
|
||||
Defaults to 5000ms.
|
||||
max_tries (int, optional): how many tries before giving up,
|
||||
if 0 then try forever. Defaults to 3.
|
||||
**kwargs: arbitrary keyword arguments provided by the
|
||||
configuration's ``database`` settings
|
||||
"""
|
||||
|
||||
dbconf = corechaindb.config['database']
|
||||
|
||||
self.host = host or dbconf['host']
|
||||
self.port = port or dbconf['port']
|
||||
self.dbname = dbname or dbconf['name']
|
||||
self.connection_timeout = connection_timeout if connection_timeout is not None \
|
||||
else dbconf['connection_timeout']
|
||||
self.max_tries = max_tries if max_tries is not None else dbconf['max_tries']
|
||||
self.max_tries_counter = range(self.max_tries) if self.max_tries != 0 else repeat(0)
|
||||
self._conn = None
|
||||
|
||||
@property
|
||||
def conn(self):
|
||||
if self._conn is None:
|
||||
self.connect()
|
||||
return self._conn
|
||||
|
||||
def run(self, query):
|
||||
"""Run a query.
|
||||
|
||||
Args:
|
||||
query: the query to run
|
||||
Raises:
|
||||
:exc:`~DuplicateKeyError`: If the query fails because of a
|
||||
duplicate key constraint.
|
||||
:exc:`~OperationFailure`: If the query fails for any other
|
||||
reason.
|
||||
:exc:`~ConnectionError`: If the connection to the database
|
||||
fails.
|
||||
"""
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
def connect(self):
|
||||
"""Try to connect to the database.
|
||||
|
||||
Raises:
|
||||
:exc:`~ConnectionError`: If the connection to the database
|
||||
fails.
|
||||
"""
|
||||
|
||||
attempt = 0
|
||||
for i in self.max_tries_counter:
|
||||
attempt += 1
|
||||
try:
|
||||
self._conn = self._connect()
|
||||
except ConnectionError as exc:
|
||||
logger.warning('Attempt %s/%s. Connection to %s:%s failed after %sms.',
|
||||
attempt, self.max_tries if self.max_tries != 0 else '∞',
|
||||
self.host, self.port, self.connection_timeout)
|
||||
if attempt == self.max_tries:
|
||||
logger.critical('Cannot connect to the Database. Giving up.')
|
||||
raise ConnectionError() from exc
|
||||
else:
|
||||
break
|
22
corechaindb/backend/exceptions.py
Normal file
22
corechaindb/backend/exceptions.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from corechaindb.exceptions import BigchainDBError
|
||||
|
||||
|
||||
class BackendError(BigchainDBError):
|
||||
"""Top level exception for any backend exception."""
|
||||
|
||||
|
||||
class ConnectionError(BackendError):
|
||||
"""Exception raised when the connection to the backend fails."""
|
||||
|
||||
|
||||
class OperationError(BackendError):
|
||||
"""Exception raised when a backend operation fails."""
|
||||
|
||||
|
||||
class DuplicateKeyError(OperationError):
|
||||
"""Exception raised when an insert fails because the key is not unique"""
|
28
corechaindb/backend/localmongodb/__init__.py
Normal file
28
corechaindb/backend/localmongodb/__init__.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""MongoDB backend implementation.
|
||||
|
||||
Contains a MongoDB-specific implementation of the
|
||||
:mod:`~corechaindb.backend.schema` and :mod:`~corechaindb.backend.query` interfaces.
|
||||
|
||||
You can specify BigchainDB to use MongoDB as its database backend by either
|
||||
setting ``database.backend`` to ``'localmongodb'`` in your configuration file, or
|
||||
setting the ``BIGCHAINDB_DATABASE_BACKEND`` environment variable to
|
||||
``'localmongodb'``.
|
||||
|
||||
MongoDB is the default database backend for BigchainDB.
|
||||
|
||||
If configured to use MongoDB, BigchainDB will automatically return instances
|
||||
of :class:`~corechaindb.backend.localmongodb.LocalMongoDBConnection` for
|
||||
:func:`~corechaindb.backend.connection.connect` and dispatch calls of the
|
||||
generic backend interfaces to the implementations in this module.
|
||||
"""
|
||||
|
||||
# Register the single dispatched modules on import.
|
||||
from corechaindb.backend.localmongodb import schema, query # noqa
|
||||
|
||||
# MongoDBConnection should always be accessed via
|
||||
# ``corechaindb.backend.connect()``.
|
136
corechaindb/backend/localmongodb/connection.py
Normal file
136
corechaindb/backend/localmongodb/connection.py
Normal file
@ -0,0 +1,136 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import logging
|
||||
from ssl import CERT_REQUIRED
|
||||
|
||||
import pymongo
|
||||
|
||||
from corechaindb.backend.connection import Connection
|
||||
from corechaindb.backend.exceptions import (DuplicateKeyError,
|
||||
OperationError,
|
||||
ConnectionError)
|
||||
from corechaindb.backend.utils import get_corechaindb_config_value
|
||||
from corechaindb.common.exceptions import ConfigurationError
|
||||
from corechaindb.utils import Lazy
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LocalMongoDBConnection(Connection):
|
||||
|
||||
def __init__(self, replicaset=None, ssl=None, login=None, password=None,
|
||||
ca_cert=None, certfile=None, keyfile=None,
|
||||
keyfile_passphrase=None, crlfile=None, **kwargs):
|
||||
"""Create a new Connection instance.
|
||||
|
||||
Args:
|
||||
replicaset (str, optional): the name of the replica set to
|
||||
connect to.
|
||||
**kwargs: arbitrary keyword arguments provided by the
|
||||
configuration's ``database`` settings
|
||||
"""
|
||||
|
||||
super().__init__(**kwargs)
|
||||
self.replicaset = replicaset or get_corechaindb_config_value('replicaset')
|
||||
self.ssl = ssl if ssl is not None else get_corechaindb_config_value('ssl', False)
|
||||
self.login = login or get_corechaindb_config_value('login')
|
||||
self.password = password or get_corechaindb_config_value('password')
|
||||
self.ca_cert = ca_cert or get_corechaindb_config_value('ca_cert')
|
||||
self.certfile = certfile or get_corechaindb_config_value('certfile')
|
||||
self.keyfile = keyfile or get_corechaindb_config_value('keyfile')
|
||||
self.keyfile_passphrase = keyfile_passphrase or get_corechaindb_config_value('keyfile_passphrase')
|
||||
self.crlfile = crlfile or get_corechaindb_config_value('crlfile')
|
||||
|
||||
@property
|
||||
def db(self):
|
||||
return self.conn[self.dbname]
|
||||
|
||||
def query(self):
|
||||
return Lazy()
|
||||
|
||||
def collection(self, name):
|
||||
"""Return a lazy object that can be used to compose a query.
|
||||
|
||||
Args:
|
||||
name (str): the name of the collection to query.
|
||||
"""
|
||||
return self.query()[self.dbname][name]
|
||||
|
||||
def run(self, query):
|
||||
try:
|
||||
try:
|
||||
return query.run(self.conn)
|
||||
except pymongo.errors.AutoReconnect:
|
||||
logger.warning('Lost connection to the database, '
|
||||
'retrying query.')
|
||||
return query.run(self.conn)
|
||||
except pymongo.errors.AutoReconnect as exc:
|
||||
raise ConnectionError from exc
|
||||
except pymongo.errors.DuplicateKeyError as exc:
|
||||
raise DuplicateKeyError from exc
|
||||
except pymongo.errors.OperationFailure as exc:
|
||||
print(f'DETAILS: {exc.details}')
|
||||
raise OperationError from exc
|
||||
|
||||
def _connect(self):
|
||||
"""Try to connect to the database.
|
||||
|
||||
Raises:
|
||||
:exc:`~ConnectionError`: If the connection to the database
|
||||
fails.
|
||||
:exc:`~AuthenticationError`: If there is a OperationFailure due to
|
||||
Authentication failure after connecting to the database.
|
||||
:exc:`~ConfigurationError`: If there is a ConfigurationError while
|
||||
connecting to the database.
|
||||
"""
|
||||
|
||||
try:
|
||||
# FYI: the connection process might raise a
|
||||
# `ServerSelectionTimeoutError`, that is a subclass of
|
||||
# `ConnectionFailure`.
|
||||
# The presence of ca_cert, certfile, keyfile, crlfile implies the
|
||||
# use of certificates for TLS connectivity.
|
||||
if self.ca_cert is None or self.certfile is None or \
|
||||
self.keyfile is None or self.crlfile is None:
|
||||
client = pymongo.MongoClient(self.host,
|
||||
self.port,
|
||||
replicaset=self.replicaset,
|
||||
serverselectiontimeoutms=self.connection_timeout,
|
||||
ssl=self.ssl,
|
||||
**MONGO_OPTS)
|
||||
if self.login is not None and self.password is not None:
|
||||
client[self.dbname].authenticate(self.login, self.password)
|
||||
else:
|
||||
logger.info('Connecting to MongoDB over TLS/SSL...')
|
||||
client = pymongo.MongoClient(self.host,
|
||||
self.port,
|
||||
replicaset=self.replicaset,
|
||||
serverselectiontimeoutms=self.connection_timeout,
|
||||
ssl=self.ssl,
|
||||
ssl_ca_certs=self.ca_cert,
|
||||
ssl_certfile=self.certfile,
|
||||
ssl_keyfile=self.keyfile,
|
||||
ssl_pem_passphrase=self.keyfile_passphrase,
|
||||
ssl_crlfile=self.crlfile,
|
||||
ssl_cert_reqs=CERT_REQUIRED,
|
||||
**MONGO_OPTS)
|
||||
if self.login is not None:
|
||||
client[self.dbname].authenticate(self.login,
|
||||
mechanism='MONGODB-X509')
|
||||
|
||||
return client
|
||||
|
||||
except (pymongo.errors.ConnectionFailure,
|
||||
pymongo.errors.OperationFailure) as exc:
|
||||
logger.info('Exception in _connect(): {}'.format(exc))
|
||||
raise ConnectionError(str(exc)) from exc
|
||||
except pymongo.errors.ConfigurationError as exc:
|
||||
raise ConfigurationError from exc
|
||||
|
||||
|
||||
MONGO_OPTS = {
|
||||
'socketTimeoutMS': 20000,
|
||||
}
|
377
corechaindb/backend/localmongodb/query.py
Normal file
377
corechaindb/backend/localmongodb/query.py
Normal file
@ -0,0 +1,377 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Query implementation for MongoDB"""
|
||||
|
||||
from pymongo import DESCENDING
|
||||
|
||||
from corechaindb import backend
|
||||
from corechaindb.backend.exceptions import DuplicateKeyError
|
||||
from corechaindb.backend.utils import module_dispatch_registrar
|
||||
from corechaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
from corechaindb.common.transaction import Transaction
|
||||
|
||||
register_query = module_dispatch_registrar(backend.query)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_transactions(conn, signed_transactions):
|
||||
return conn.run(conn.collection('transactions')
|
||||
.insert_many(signed_transactions))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_transaction(conn, transaction_id):
|
||||
return conn.run(
|
||||
conn.collection('transactions')
|
||||
.find_one({'id': transaction_id}, {'_id': 0}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_transactions(conn, transaction_ids):
|
||||
try:
|
||||
return conn.run(
|
||||
conn.collection('transactions')
|
||||
.find({'id': {'$in': transaction_ids}},
|
||||
projection={'_id': False}))
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_metadatas(conn, metadata):
|
||||
return conn.run(
|
||||
conn.collection('metadata')
|
||||
.insert_many(metadata, ordered=False))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_metadata(conn, transaction_ids):
|
||||
return conn.run(
|
||||
conn.collection('metadata')
|
||||
.find({'id': {'$in': transaction_ids}},
|
||||
projection={'_id': False}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_asset(conn, asset):
|
||||
try:
|
||||
return conn.run(
|
||||
conn.collection('assets')
|
||||
.insert_one(asset))
|
||||
except DuplicateKeyError:
|
||||
pass
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_assets(conn, assets):
|
||||
return conn.run(
|
||||
conn.collection('assets')
|
||||
.insert_many(assets, ordered=False))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_asset(conn, asset_id):
|
||||
try:
|
||||
return conn.run(
|
||||
conn.collection('assets')
|
||||
.find_one({'id': asset_id}, {'_id': 0, 'id': 0}))
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_assets(conn, asset_ids):
|
||||
return conn.run(
|
||||
conn.collection('assets')
|
||||
.find({'id': {'$in': asset_ids}},
|
||||
projection={'_id': False}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_spent(conn, transaction_id, output):
|
||||
query = {'inputs':
|
||||
{'$elemMatch':
|
||||
{'$and': [{'fulfills.transaction_id': transaction_id},
|
||||
{'fulfills.output_index': output}]}}}
|
||||
|
||||
return conn.run(
|
||||
conn.collection('transactions')
|
||||
.find(query, {'_id': 0}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_latest_block(conn):
|
||||
return conn.run(
|
||||
conn.collection('blocks')
|
||||
.find_one(projection={'_id': False},
|
||||
sort=[('height', DESCENDING)]))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_block(conn, block):
|
||||
try:
|
||||
return conn.run(
|
||||
conn.collection('blocks')
|
||||
.insert_one(block))
|
||||
except DuplicateKeyError:
|
||||
pass
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_txids_filtered(conn, asset_id, operation=None, last_tx=None):
|
||||
|
||||
match = {
|
||||
Transaction.CREATE: {'operation': 'CREATE', 'id': asset_id},
|
||||
Transaction.TRANSFER: {'operation': 'TRANSFER', 'asset.id': asset_id},
|
||||
None: {'$or': [{'asset.id': asset_id}, {'id': asset_id}]},
|
||||
}[operation]
|
||||
|
||||
cursor = conn.run(conn.collection('transactions').find(match))
|
||||
|
||||
if last_tx:
|
||||
cursor = cursor.sort([('$natural', DESCENDING)]).limit(1)
|
||||
|
||||
return (elem['id'] for elem in cursor)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def text_search(conn, search, *, language='english', case_sensitive=False,
|
||||
diacritic_sensitive=False, text_score=False, limit=0, table='assets'):
|
||||
cursor = conn.run(
|
||||
conn.collection(table)
|
||||
.find({'$text': {
|
||||
'$search': search,
|
||||
'$language': language,
|
||||
'$caseSensitive': case_sensitive,
|
||||
'$diacriticSensitive': diacritic_sensitive}},
|
||||
{'score': {'$meta': 'textScore'}, '_id': False})
|
||||
.sort([('score', {'$meta': 'textScore'})])
|
||||
.limit(limit))
|
||||
|
||||
if text_score:
|
||||
return cursor
|
||||
|
||||
return (_remove_text_score(obj) for obj in cursor)
|
||||
|
||||
|
||||
def _remove_text_score(asset):
|
||||
asset.pop('score', None)
|
||||
return asset
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_owned_ids(conn, owner):
|
||||
cursor = conn.run(
|
||||
conn.collection('transactions').aggregate([
|
||||
{'$match': {'outputs.public_keys': owner}},
|
||||
{'$project': {'_id': False}}
|
||||
]))
|
||||
return cursor
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_spending_transactions(conn, inputs):
|
||||
transaction_ids = [i['transaction_id'] for i in inputs]
|
||||
output_indexes = [i['output_index'] for i in inputs]
|
||||
query = {'inputs':
|
||||
{'$elemMatch':
|
||||
{'$and':
|
||||
[
|
||||
{'fulfills.transaction_id': {'$in': transaction_ids}},
|
||||
{'fulfills.output_index': {'$in': output_indexes}}
|
||||
]}}}
|
||||
|
||||
cursor = conn.run(
|
||||
conn.collection('transactions').find(query, {'_id': False}))
|
||||
return cursor
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_block(conn, block_id):
|
||||
return conn.run(
|
||||
conn.collection('blocks')
|
||||
.find_one({'height': block_id},
|
||||
projection={'_id': False}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_block_with_transaction(conn, txid):
|
||||
return conn.run(
|
||||
conn.collection('blocks')
|
||||
.find({'transactions': txid},
|
||||
projection={'_id': False, 'height': True}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def delete_transactions(conn, txn_ids):
|
||||
conn.run(conn.collection('assets').delete_many({'id': {'$in': txn_ids}}))
|
||||
conn.run(conn.collection('metadata').delete_many({'id': {'$in': txn_ids}}))
|
||||
conn.run(conn.collection('transactions').delete_many({'id': {'$in': txn_ids}}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_unspent_outputs(conn, *unspent_outputs):
|
||||
if unspent_outputs:
|
||||
try:
|
||||
return conn.run(
|
||||
conn.collection('utxos').insert_many(
|
||||
unspent_outputs,
|
||||
ordered=False,
|
||||
)
|
||||
)
|
||||
except DuplicateKeyError:
|
||||
# TODO log warning at least
|
||||
pass
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def delete_unspent_outputs(conn, *unspent_outputs):
|
||||
if unspent_outputs:
|
||||
return conn.run(
|
||||
conn.collection('utxos').delete_many({
|
||||
'$or': [{
|
||||
'$and': [
|
||||
{'transaction_id': unspent_output['transaction_id']},
|
||||
{'output_index': unspent_output['output_index']},
|
||||
],
|
||||
} for unspent_output in unspent_outputs]
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_unspent_outputs(conn, *, query=None):
|
||||
if query is None:
|
||||
query = {}
|
||||
return conn.run(conn.collection('utxos').find(query,
|
||||
projection={'_id': False}))
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_pre_commit_state(conn, state):
|
||||
return conn.run(
|
||||
conn.collection('pre_commit')
|
||||
.replace_one({}, state, upsert=True)
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_pre_commit_state(conn):
|
||||
return conn.run(conn.collection('pre_commit').find_one())
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_validator_set(conn, validators_update):
|
||||
height = validators_update['height']
|
||||
return conn.run(
|
||||
conn.collection('validators').replace_one(
|
||||
{'height': height},
|
||||
validators_update,
|
||||
upsert=True
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def delete_validator_set(conn, height):
|
||||
return conn.run(
|
||||
conn.collection('validators').delete_many({'height': height})
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_election(conn, election_id, height, is_concluded):
|
||||
return conn.run(
|
||||
conn.collection('elections').replace_one(
|
||||
{'election_id': election_id,
|
||||
'height': height},
|
||||
{'election_id': election_id,
|
||||
'height': height,
|
||||
'is_concluded': is_concluded},
|
||||
upsert=True,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_elections(conn, elections):
|
||||
return conn.run(
|
||||
conn.collection('elections').insert_many(elections)
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def delete_elections(conn, height):
|
||||
return conn.run(
|
||||
conn.collection('elections').delete_many({'height': height})
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_validator_set(conn, height=None):
|
||||
query = {}
|
||||
if height is not None:
|
||||
query = {'height': {'$lte': height}}
|
||||
|
||||
cursor = conn.run(
|
||||
conn.collection('validators')
|
||||
.find(query, projection={'_id': False})
|
||||
.sort([('height', DESCENDING)])
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
return next(cursor, None)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_election(conn, election_id):
|
||||
query = {'election_id': election_id}
|
||||
|
||||
return conn.run(
|
||||
conn.collection('elections')
|
||||
.find_one(query, projection={'_id': False},
|
||||
sort=[('height', DESCENDING)])
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_asset_tokens_for_public_key(conn, asset_id, public_key):
|
||||
query = {'outputs.public_keys': [public_key],
|
||||
'asset.id': asset_id}
|
||||
|
||||
cursor = conn.run(
|
||||
conn.collection('transactions').aggregate([
|
||||
{'$match': query},
|
||||
{'$project': {'_id': False}}
|
||||
]))
|
||||
return cursor
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def store_abci_chain(conn, height, chain_id, is_synced=True):
|
||||
return conn.run(
|
||||
conn.collection('abci_chains').replace_one(
|
||||
{'height': height},
|
||||
{'height': height, 'chain_id': chain_id,
|
||||
'is_synced': is_synced},
|
||||
upsert=True,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def delete_abci_chain(conn, height):
|
||||
return conn.run(
|
||||
conn.collection('abci_chains').delete_many({'height': height})
|
||||
)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def get_latest_abci_chain(conn):
|
||||
return conn.run(
|
||||
conn.collection('abci_chains')
|
||||
.find_one(projection={'_id': False}, sort=[('height', DESCENDING)])
|
||||
)
|
90
corechaindb/backend/localmongodb/schema.py
Normal file
90
corechaindb/backend/localmongodb/schema.py
Normal file
@ -0,0 +1,90 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Utils to initialize and drop the database."""
|
||||
|
||||
import logging
|
||||
|
||||
from pymongo import ASCENDING, DESCENDING, TEXT
|
||||
from pymongo.errors import CollectionInvalid
|
||||
|
||||
from corechaindb import backend
|
||||
from corechaindb.backend.utils import module_dispatch_registrar
|
||||
from corechaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
register_schema = module_dispatch_registrar(backend.schema)
|
||||
|
||||
|
||||
INDEXES = {
|
||||
'transactions': [
|
||||
('id', dict(unique=True, name='transaction_id')),
|
||||
('asset.id', dict(name='asset_id')),
|
||||
('outputs.public_keys', dict(name='outputs')),
|
||||
([('inputs.fulfills.transaction_id', ASCENDING),
|
||||
('inputs.fulfills.output_index', ASCENDING)], dict(name='inputs')),
|
||||
],
|
||||
'assets': [
|
||||
('id', dict(name='asset_id', unique=True)),
|
||||
([('$**', TEXT)], dict(name='text')),
|
||||
],
|
||||
'blocks': [
|
||||
([('height', DESCENDING)], dict(name='height', unique=True)),
|
||||
],
|
||||
'metadata': [
|
||||
('id', dict(name='transaction_id', unique=True)),
|
||||
([('$**', TEXT)], dict(name='text')),
|
||||
],
|
||||
'utxos': [
|
||||
([('transaction_id', ASCENDING),
|
||||
('output_index', ASCENDING)], dict(name='utxo', unique=True)),
|
||||
],
|
||||
'pre_commit': [
|
||||
('height', dict(name='height', unique=True)),
|
||||
],
|
||||
'elections': [
|
||||
([('height', DESCENDING), ('election_id', ASCENDING)],
|
||||
dict(name='election_id_height', unique=True)),
|
||||
],
|
||||
'validators': [
|
||||
('height', dict(name='height', unique=True)),
|
||||
],
|
||||
'abci_chains': [
|
||||
('height', dict(name='height', unique=True)),
|
||||
('chain_id', dict(name='chain_id', unique=True)),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@register_schema(LocalMongoDBConnection)
|
||||
def create_database(conn, dbname):
|
||||
logger.info('Create database `%s`.', dbname)
|
||||
# TODO: read and write concerns can be declared here
|
||||
conn.conn.get_database(dbname)
|
||||
|
||||
|
||||
@register_schema(LocalMongoDBConnection)
|
||||
def create_tables(conn, dbname):
|
||||
for table_name in backend.schema.TABLES:
|
||||
# create the table
|
||||
# TODO: read and write concerns can be declared here
|
||||
try:
|
||||
logger.info(f'Create `{table_name}` table.')
|
||||
conn.conn[dbname].create_collection(table_name)
|
||||
except CollectionInvalid:
|
||||
logger.info(f'Collection {table_name} already exists.')
|
||||
create_indexes(conn, dbname, table_name, INDEXES[table_name])
|
||||
|
||||
|
||||
def create_indexes(conn, dbname, collection, indexes):
|
||||
logger.info(f'Ensure secondary indexes for `{collection}`.')
|
||||
for fields, kwargs in indexes:
|
||||
conn.conn[dbname][collection].create_index(fields, **kwargs)
|
||||
|
||||
|
||||
@register_schema(LocalMongoDBConnection)
|
||||
def drop_database(conn, dbname):
|
||||
conn.conn.drop_database(dbname)
|
430
corechaindb/backend/query.py
Normal file
430
corechaindb/backend/query.py
Normal file
@ -0,0 +1,430 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Query interfaces for backends."""
|
||||
|
||||
from functools import singledispatch
|
||||
|
||||
from corechaindb.backend.exceptions import OperationError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_asset(connection, asset):
|
||||
"""Write an asset to the asset table.
|
||||
|
||||
Args:
|
||||
asset (dict): the asset.
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_assets(connection, assets):
|
||||
"""Write a list of assets to the assets table.
|
||||
|
||||
Args:
|
||||
assets (list): a list of assets to write.
|
||||
|
||||
Returns:
|
||||
The database response.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_metadatas(connection, metadata):
|
||||
"""Write a list of metadata to metadata table.
|
||||
|
||||
Args:
|
||||
metadata (list): list of metadata.
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_transactions(connection, signed_transactions):
|
||||
"""Store the list of transactions."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_transaction(connection, transaction_id):
|
||||
"""Get a transaction from the transactions table.
|
||||
|
||||
Args:
|
||||
transaction_id (str): the id of the transaction.
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_transactions(connection, transaction_ids):
|
||||
"""Get transactions from the transactions table.
|
||||
|
||||
Args:
|
||||
transaction_ids (list): list of transaction ids to fetch
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_asset(connection, asset_id):
|
||||
"""Get a transaction from the transactions table.
|
||||
|
||||
Args:
|
||||
asset_id (str): the id of the asset
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_spent(connection, transaction_id, condition_id):
|
||||
"""Check if a `txid` was already used as an input.
|
||||
|
||||
A transaction can be used as an input for another transaction. Bigchain
|
||||
needs to make sure that a given `txid` is only used once.
|
||||
|
||||
Args:
|
||||
transaction_id (str): The id of the transaction.
|
||||
condition_id (int): The index of the condition in the respective
|
||||
transaction.
|
||||
|
||||
Returns:
|
||||
The transaction that used the `txid` as an input else `None`
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_spending_transactions(connection, inputs):
|
||||
"""Return transactions which spend given inputs
|
||||
|
||||
Args:
|
||||
inputs (list): list of {txid, output}
|
||||
|
||||
Returns:
|
||||
Iterator of (block_ids, transaction) for transactions that
|
||||
spend given inputs.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_owned_ids(connection, owner):
|
||||
"""Retrieve a list of `txids` that can we used has inputs.
|
||||
|
||||
Args:
|
||||
owner (str): base58 encoded public key.
|
||||
|
||||
Returns:
|
||||
Iterator of (block_id, transaction) for transactions
|
||||
that list given owner in conditions.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_block(connection, block_id):
|
||||
"""Get a block from the bigchain table.
|
||||
|
||||
Args:
|
||||
block_id (str): block id of the block to get
|
||||
|
||||
Returns:
|
||||
block (dict): the block or `None`
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_block_with_transaction(connection, txid):
|
||||
"""Get a block containing transaction id `txid`
|
||||
|
||||
Args:
|
||||
txid (str): id of transaction to be searched.
|
||||
|
||||
Returns:
|
||||
block_id (int): the block id or `None`
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_metadata(connection, transaction_ids):
|
||||
"""Get a list of metadata from the metadata table.
|
||||
|
||||
Args:
|
||||
transaction_ids (list): a list of ids for the metadata to be retrieved from
|
||||
the database.
|
||||
|
||||
Returns:
|
||||
metadata (list): the list of returned metadata.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_assets(connection, asset_ids):
|
||||
"""Get a list of assets from the assets table.
|
||||
Args:
|
||||
asset_ids (list): a list of ids for the assets to be retrieved from
|
||||
the database.
|
||||
Returns:
|
||||
assets (list): the list of returned assets.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_txids_filtered(connection, asset_id, operation=None):
|
||||
"""Return all transactions for a particular asset id and optional operation.
|
||||
|
||||
Args:
|
||||
asset_id (str): ID of transaction that defined the asset
|
||||
operation (str) (optional): Operation to filter on
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def text_search(conn, search, *, language='english', case_sensitive=False,
|
||||
diacritic_sensitive=False, text_score=False, limit=0, table=None):
|
||||
"""Return all the assets that match the text search.
|
||||
|
||||
The results are sorted by text score.
|
||||
For more information about the behavior of text search on MongoDB see
|
||||
https://docs.mongodb.com/manual/reference/operator/query/text/#behavior
|
||||
|
||||
Args:
|
||||
search (str): Text search string to query the text index
|
||||
language (str, optional): The language for the search and the rules for
|
||||
stemmer and tokenizer. If the language is ``None`` text search uses
|
||||
simple tokenization and no stemming.
|
||||
case_sensitive (bool, optional): Enable or disable case sensitive
|
||||
search.
|
||||
diacritic_sensitive (bool, optional): Enable or disable case sensitive
|
||||
diacritic search.
|
||||
text_score (bool, optional): If ``True`` returns the text score with
|
||||
each document.
|
||||
limit (int, optional): Limit the number of returned documents.
|
||||
|
||||
Returns:
|
||||
:obj:`list` of :obj:`dict`: a list of assets
|
||||
|
||||
Raises:
|
||||
OperationError: If the backend does not support text search
|
||||
"""
|
||||
|
||||
raise OperationError('This query is only supported when running '
|
||||
'BigchainDB with MongoDB as the backend.')
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_latest_block(conn):
|
||||
"""Get the latest commited block i.e. block with largest height"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_block(conn, block):
|
||||
"""Write a new block to the `blocks` table
|
||||
|
||||
Args:
|
||||
block (dict): block with current height and block hash.
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_unspent_outputs(connection, unspent_outputs):
|
||||
"""Store unspent outputs in ``utxo_set`` table."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def delete_unspent_outputs(connection, unspent_outputs):
|
||||
"""Delete unspent outputs in ``utxo_set`` table."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def delete_transactions(conn, txn_ids):
|
||||
"""Delete transactions from database
|
||||
|
||||
Args:
|
||||
txn_ids (list): list of transaction ids
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_unspent_outputs(connection, *, query=None):
|
||||
"""Retrieves unspent outputs.
|
||||
|
||||
Args:
|
||||
query (dict): An optional parameter to filter the result set.
|
||||
Defaults to ``None``, which means that all UTXO records
|
||||
will be returned.
|
||||
|
||||
Returns:
|
||||
Generator yielding unspent outputs (UTXO set) according to the
|
||||
given query.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_pre_commit_state(connection, state):
|
||||
"""Store pre-commit state.
|
||||
|
||||
Args:
|
||||
state (dict): pre-commit state.
|
||||
|
||||
Returns:
|
||||
The result of the operation.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_pre_commit_state(connection):
|
||||
"""Get pre-commit state.
|
||||
|
||||
Returns:
|
||||
Document representing the pre-commit state.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_validator_set(conn, validator_update):
|
||||
"""Store updated validator set"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def delete_validator_set(conn, height):
|
||||
"""Delete the validator set at the given height."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_election(conn, election_id, height, is_concluded):
|
||||
"""Store election record"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_elections(conn, elections):
|
||||
"""Store election records in bulk"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def delete_elections(conn, height):
|
||||
"""Delete all election records at the given height"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_validator_set(conn, height):
|
||||
"""Get validator set for a given `height`, if `height` is not specified
|
||||
then return the latest validator set
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_election(conn, election_id):
|
||||
"""Return the election record
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_asset_tokens_for_public_key(connection, asset_id, public_key):
|
||||
"""Retrieve a list of tokens of type `asset_id` that are owned by the `public_key`.
|
||||
Args:
|
||||
asset_id (str): Id of the token.
|
||||
public_key (str): base58 encoded public key
|
||||
Returns:
|
||||
Iterator of transaction that list given owner in conditions.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def store_abci_chain(conn, height, chain_id, is_synced=True):
|
||||
"""Create or update an ABCI chain at the given height.
|
||||
Usually invoked in the beginning of the ABCI communications (height=0)
|
||||
or when ABCI client (like Tendermint) is migrated (any height).
|
||||
|
||||
Args:
|
||||
is_synced: True if the chain is known by both ABCI client and server
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def delete_abci_chain(conn, height):
|
||||
"""Delete the ABCI chain at the given height."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def get_latest_abci_chain(conn):
|
||||
"""Returns the ABCI chain stored at the biggest height, if any,
|
||||
None otherwise.
|
||||
"""
|
||||
raise NotImplementedError
|
128
corechaindb/backend/schema.py
Normal file
128
corechaindb/backend/schema.py
Normal file
@ -0,0 +1,128 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Database creation and schema-providing interfaces for backends."""
|
||||
|
||||
from functools import singledispatch
|
||||
import logging
|
||||
|
||||
import corechaindb
|
||||
from corechaindb.backend.connection import connect
|
||||
from corechaindb.common.exceptions import ValidationError
|
||||
from corechaindb.common.utils import validate_all_values_for_key_in_obj, validate_all_values_for_key_in_list
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Tables/collections that every backend database must create
|
||||
TABLES = ('transactions', 'blocks', 'assets', 'metadata',
|
||||
'validators', 'elections', 'pre_commit', 'utxos', 'abci_chains')
|
||||
|
||||
VALID_LANGUAGES = ('danish', 'dutch', 'english', 'finnish', 'french', 'german',
|
||||
'hungarian', 'italian', 'norwegian', 'portuguese', 'romanian',
|
||||
'russian', 'spanish', 'swedish', 'turkish', 'none',
|
||||
'da', 'nl', 'en', 'fi', 'fr', 'de', 'hu', 'it', 'nb', 'pt',
|
||||
'ro', 'ru', 'es', 'sv', 'tr')
|
||||
|
||||
|
||||
@singledispatch
|
||||
def create_database(connection, dbname):
|
||||
"""Create database to be used by BigchainDB.
|
||||
|
||||
Args:
|
||||
dbname (str): the name of the database to create.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def create_tables(connection, dbname):
|
||||
"""Create the tables to be used by BigchainDB.
|
||||
|
||||
Args:
|
||||
dbname (str): the name of the database to create tables for.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@singledispatch
|
||||
def drop_database(connection, dbname):
|
||||
"""Drop the database used by BigchainDB.
|
||||
|
||||
Args:
|
||||
dbname (str): the name of the database to drop.
|
||||
|
||||
Raises:
|
||||
:exc:`~DatabaseDoesNotExist`: If the given :attr:`dbname` does not
|
||||
exist as a database.
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def init_database(connection=None, dbname=None):
|
||||
"""Initialize the configured backend for use with BigchainDB.
|
||||
|
||||
Creates a database with :attr:`dbname` with any required tables
|
||||
and supporting indexes.
|
||||
|
||||
Args:
|
||||
connection (:class:`~corechaindb.backend.connection.Connection`): an
|
||||
existing connection to use to initialize the database.
|
||||
Creates one if not given.
|
||||
dbname (str): the name of the database to create.
|
||||
Defaults to the database name given in the BigchainDB
|
||||
configuration.
|
||||
"""
|
||||
|
||||
connection = connection or connect()
|
||||
dbname = dbname or corechaindb.config['database']['name']
|
||||
|
||||
create_database(connection, dbname)
|
||||
create_tables(connection, dbname)
|
||||
|
||||
|
||||
def validate_language_key(obj, key):
|
||||
"""Validate all nested "language" key in `obj`.
|
||||
|
||||
Args:
|
||||
obj (dict): dictionary whose "language" key is to be validated.
|
||||
|
||||
Returns:
|
||||
None: validation successful
|
||||
|
||||
Raises:
|
||||
ValidationError: will raise exception in case language is not valid.
|
||||
"""
|
||||
backend = corechaindb.config['database']['backend']
|
||||
|
||||
if backend == 'localmongodb':
|
||||
data = obj.get(key, {})
|
||||
if isinstance(data, dict):
|
||||
validate_all_values_for_key_in_obj(data, 'language', validate_language)
|
||||
elif isinstance(data, list):
|
||||
validate_all_values_for_key_in_list(data, 'language', validate_language)
|
||||
|
||||
|
||||
def validate_language(value):
|
||||
"""Check if `value` is a valid language.
|
||||
https://docs.mongodb.com/manual/reference/text-search-languages/
|
||||
|
||||
Args:
|
||||
value (str): language to validated
|
||||
|
||||
Returns:
|
||||
None: validation successful
|
||||
|
||||
Raises:
|
||||
ValidationError: will raise exception in case language is not valid.
|
||||
"""
|
||||
if value not in VALID_LANGUAGES:
|
||||
error_str = ('MongoDB does not support text search for the '
|
||||
'language "{}". If you do not understand this error '
|
||||
'message then please rename key/field "language" to '
|
||||
'something else like "lang".').format(value)
|
||||
raise ValidationError(error_str)
|
39
corechaindb/backend/utils.py
Normal file
39
corechaindb/backend/utils.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright © 2024 Atlantic Algorithms Ltd.,
|
||||
# CoreChainDB and Atlantic Algorithms Ltd. software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import corechaindb
|
||||
|
||||
|
||||
class ModuleDispatchRegistrationError(Exception):
|
||||
"""Raised when there is a problem registering dispatched functions for a
|
||||
module
|
||||
"""
|
||||
|
||||
|
||||
def module_dispatch_registrar(module):
|
||||
def dispatch_wrapper(obj_type):
|
||||
def wrapper(func):
|
||||
func_name = func.__name__
|
||||
try:
|
||||
dispatch_registrar = getattr(module, func_name)
|
||||
return dispatch_registrar.register(obj_type)(func)
|
||||
except AttributeError as ex:
|
||||
raise ModuleDispatchRegistrationError(
|
||||
('`{module}` does not contain a single-dispatchable '
|
||||
'function named `{func}`. The module being registered '
|
||||
'was not implemented correctly!').format(
|
||||
func=func_name, module=module.__name__)) from ex
|
||||
|
||||
return wrapper
|
||||
|
||||
return dispatch_wrapper
|
||||
|
||||
|
||||
def get_corechaindb_config_value(key, default_value=None):
|
||||
return corechaindb.config['database'].get(key, default_value)
|
||||
|
||||
|
||||
def get_corechaindb_config_value_or_key_error(key):
|
||||
return corechaindb.config['database'][key]
|
42
corechaindb/bigchaindb/README.md
Normal file
42
corechaindb/bigchaindb/README.md
Normal file
@ -0,0 +1,42 @@
|
||||
<!---
|
||||
Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
BigchainDB and IPDB software contributors.
|
||||
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
--->
|
||||
|
||||
# Overview
|
||||
|
||||
A high-level description of the files and subdirectories of BigchainDB.
|
||||
|
||||
## Files
|
||||
|
||||
### [`lib.py`](lib.py)
|
||||
|
||||
The `BigchainDB` class is defined here. Most node-level operations and database interactions are found in this file. This is the place to start if you are interested in implementing a server API, since many of these class methods concern BigchainDB interacting with the outside world.
|
||||
|
||||
### [`models.py`](./models.py)
|
||||
|
||||
`Block`, `Transaction`, and `Asset` classes are defined here. The classes mirror the block and transaction structure from the [documentation](https://docs.corechaindb.com/projects/server/en/latest/data-models/index.html), but also include methods for validation and signing.
|
||||
|
||||
### [`validation.py`](./validation.py)
|
||||
|
||||
Base class for validation methods (verification of votes, blocks, and transactions). The actual logic is mostly found in `transaction` and `block` models, defined in [`models.py`](./models.py).
|
||||
|
||||
### [`processes.py`](./processes.py)
|
||||
|
||||
Entry point for the BigchainDB process, after initialization. All subprocesses are started here: processes to handle new blocks, votes, etc.
|
||||
|
||||
### [`config_utils.py`](./config_utils.py)
|
||||
|
||||
Methods for managing the configuration, including loading configuration files, automatically generating the configuration, and keeping the configuration consistent across BigchainDB instances.
|
||||
|
||||
## Folders
|
||||
|
||||
### [`commands`](./commands)
|
||||
|
||||
Contains code for the [CLI](https://docs.corechaindb.com/projects/server/en/latest/server-reference/corechaindb-cli.html) for BigchainDB.
|
||||
|
||||
### [`db`](./db)
|
||||
|
||||
Code for building the database connection, creating indexes, and other database setup tasks.
|
@ -6,17 +6,17 @@
|
||||
import copy
|
||||
import logging
|
||||
|
||||
from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config
|
||||
from bigchaindb.lib import BigchainDB # noqa
|
||||
from bigchaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from bigchaindb.version import __version__ # noqa
|
||||
from bigchaindb.core import App # noqa
|
||||
from corechaindb.log import DEFAULT_LOGGING_CONFIG as log_config
|
||||
from corechaindb.lib import BigchainDB # noqa
|
||||
from corechaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from corechaindb.version import __version__ # noqa
|
||||
from corechaindb.core import App # noqa
|
||||
|
||||
# from functools import reduce
|
||||
# PORT_NUMBER = reduce(lambda x, y: x * y, map(ord, 'BigchainDB')) % 2**16
|
||||
# basically, the port number is 9984
|
||||
|
||||
# The following variable is used by `bigchaindb configure` to
|
||||
# The following variable is used by `corechaindb configure` to
|
||||
# prompt the user for database values. We cannot rely on
|
||||
# _base_database_localmongodb.keys() because dicts are unordered.
|
||||
# I tried to configure
|
||||
@ -91,13 +91,13 @@ config = {
|
||||
}
|
||||
|
||||
# We need to maintain a backup copy of the original config dict in case
|
||||
# the user wants to reconfigure the node. Check ``bigchaindb.config_utils``
|
||||
# the user wants to reconfigure the node. Check ``corechaindb.config_utils``
|
||||
# for more info.
|
||||
_config = copy.deepcopy(config)
|
||||
from bigchaindb.common.transaction import Transaction # noqa
|
||||
from bigchaindb import models # noqa
|
||||
from bigchaindb.upsert_validator import ValidatorElection # noqa
|
||||
from bigchaindb.elections.vote import Vote # noqa
|
||||
from corechaindb.common.transaction import Transaction # noqa
|
||||
from corechaindb import models # noqa
|
||||
from corechaindb.upsert_validator import ValidatorElection # noqa
|
||||
from corechaindb.elections.vote import Vote # noqa
|
||||
|
||||
Transaction.register_type(Transaction.CREATE, models.Transaction)
|
||||
Transaction.register_type(Transaction.TRANSFER, models.Transaction)
|
51
corechaindb/bigchaindb/backend/README.md
Normal file
51
corechaindb/bigchaindb/backend/README.md
Normal file
@ -0,0 +1,51 @@
|
||||
<!---
|
||||
Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
BigchainDB and IPDB software contributors.
|
||||
SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
--->
|
||||
|
||||
# Backend Interfaces
|
||||
|
||||
## Structure
|
||||
|
||||
- [`connection.py`](./connection.py): Database connection-related interfaces
|
||||
- [`query.py`](./query.py): Database query-related interfaces, dispatched through single-dispatch
|
||||
- [`schema.py`](./schema.py): Database setup and schema-related interfaces, dispatched through
|
||||
single-dispatch
|
||||
|
||||
Built-in implementations (e.g. [MongoDB's](./localmongodb)) are provided in sub-directories and
|
||||
have their connection type's location exposed as `BACKENDS` in [`connection.py`](./connection.py).
|
||||
|
||||
## Single-Dispatched Interfaces
|
||||
|
||||
The architecture of this module is based heavily upon Python's newly-introduced [single-dispatch
|
||||
generic functions](https://www.python.org/dev/peps/pep-0443/). Single-dispatch is convenient,
|
||||
because it allows Python, rather than something we design ourselves, to manage the dispatching of
|
||||
generic functions based on certain conditions being met (e.g. the database backend to use).
|
||||
|
||||
To see what this looks like in BigchainDB, first note that our backend interfaces have been
|
||||
configured to dispatch based on a backend's **connection type**.
|
||||
|
||||
Call `corechaindb.backend.connect()` to create an instance of a `Connection`:
|
||||
|
||||
```python
|
||||
from corechaindb.backend import connect
|
||||
connection = connect() # By default, uses the current configuration for backend, host, port, etc.
|
||||
```
|
||||
|
||||
Then, we can call a backend function by directly calling its interface:
|
||||
|
||||
```python
|
||||
from corechaindb.backend import query
|
||||
query.write_transaction(connection, ...)
|
||||
```
|
||||
|
||||
Notice that we don't need to care about which backend implementation to use or how to access it.
|
||||
Code can simply call the base interface function with a `Connection` instance, and single-dispatch
|
||||
will handle routing the call to the actual implementation.
|
||||
|
||||
BigchainDB will load and register the configured backend's implementation automatically (see
|
||||
`corechaindb.backend.connect()`), so you should always just be able to call an interface function if
|
||||
you have a `Connection` instance. A few helper utilities (see [`backend/utils.py`](./utils.py)) are
|
||||
also provided to make registering new backend implementations easier.
|
@ -12,6 +12,6 @@ configuration or the ``BIGCHAINDB_DATABASE_BACKEND`` environment variable.
|
||||
"""
|
||||
|
||||
# Include the backend interfaces
|
||||
from bigchaindb.backend import schema, query # noqa
|
||||
from corechaindb.backend import schema, query # noqa
|
||||
|
||||
from bigchaindb.backend.connection import connect # noqa
|
||||
from corechaindb.backend.connection import connect # noqa
|
@ -7,13 +7,13 @@ import logging
|
||||
from importlib import import_module
|
||||
from itertools import repeat
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.backend.exceptions import ConnectionError
|
||||
from bigchaindb.backend.utils import get_bigchaindb_config_value, get_bigchaindb_config_value_or_key_error
|
||||
from bigchaindb.common.exceptions import ConfigurationError
|
||||
import corechaindb
|
||||
from corechaindb.backend.exceptions import ConnectionError
|
||||
from corechaindb.backend.utils import get_corechaindb_config_value, get_corechaindb_config_value_or_key_error
|
||||
from corechaindb.common.exceptions import ConfigurationError
|
||||
|
||||
BACKENDS = {
|
||||
'localmongodb': 'bigchaindb.backend.localmongodb.connection.LocalMongoDBConnection',
|
||||
'localmongodb': 'corechaindb.backend.localmongodb.connection.LocalMongoDBConnection',
|
||||
}
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -37,7 +37,7 @@ def connect(backend=None, host=None, port=None, name=None, max_tries=None,
|
||||
MongoDB connections).
|
||||
|
||||
Returns:
|
||||
An instance of :class:`~bigchaindb.backend.connection.Connection`
|
||||
An instance of :class:`~corechaindb.backend.connection.Connection`
|
||||
based on the given (or defaulted) :attr:`backend`.
|
||||
|
||||
Raises:
|
||||
@ -48,10 +48,10 @@ def connect(backend=None, host=None, port=None, name=None, max_tries=None,
|
||||
Authentication failure after connecting to the database.
|
||||
"""
|
||||
|
||||
backend = backend or get_bigchaindb_config_value_or_key_error('backend')
|
||||
host = host or get_bigchaindb_config_value_or_key_error('host')
|
||||
port = port or get_bigchaindb_config_value_or_key_error('port')
|
||||
dbname = name or get_bigchaindb_config_value_or_key_error('name')
|
||||
backend = backend or get_corechaindb_config_value_or_key_error('backend')
|
||||
host = host or get_corechaindb_config_value_or_key_error('host')
|
||||
port = port or get_corechaindb_config_value_or_key_error('port')
|
||||
dbname = name or get_corechaindb_config_value_or_key_error('name')
|
||||
# Not sure how to handle this here. This setting is only relevant for
|
||||
# mongodb.
|
||||
# I added **kwargs for both RethinkDBConnection and MongoDBConnection
|
||||
@ -61,15 +61,15 @@ def connect(backend=None, host=None, port=None, name=None, max_tries=None,
|
||||
# UPD: RethinkDBConnection is not here anymore cause we no longer support RethinkDB.
|
||||
# The problem described above might be reconsidered next time we introduce a backend,
|
||||
# if it ever happens.
|
||||
replicaset = replicaset or get_bigchaindb_config_value('replicaset')
|
||||
ssl = ssl if ssl is not None else get_bigchaindb_config_value('ssl', False)
|
||||
login = login or get_bigchaindb_config_value('login')
|
||||
password = password or get_bigchaindb_config_value('password')
|
||||
ca_cert = ca_cert or get_bigchaindb_config_value('ca_cert')
|
||||
certfile = certfile or get_bigchaindb_config_value('certfile')
|
||||
keyfile = keyfile or get_bigchaindb_config_value('keyfile')
|
||||
keyfile_passphrase = keyfile_passphrase or get_bigchaindb_config_value('keyfile_passphrase', None)
|
||||
crlfile = crlfile or get_bigchaindb_config_value('crlfile')
|
||||
replicaset = replicaset or get_corechaindb_config_value('replicaset')
|
||||
ssl = ssl if ssl is not None else get_corechaindb_config_value('ssl', False)
|
||||
login = login or get_corechaindb_config_value('login')
|
||||
password = password or get_corechaindb_config_value('password')
|
||||
ca_cert = ca_cert or get_corechaindb_config_value('ca_cert')
|
||||
certfile = certfile or get_corechaindb_config_value('certfile')
|
||||
keyfile = keyfile or get_corechaindb_config_value('keyfile')
|
||||
keyfile_passphrase = keyfile_passphrase or get_corechaindb_config_value('keyfile_passphrase', None)
|
||||
crlfile = crlfile or get_corechaindb_config_value('crlfile')
|
||||
|
||||
try:
|
||||
module_name, _, class_name = BACKENDS[backend].rpartition('.')
|
||||
@ -113,7 +113,7 @@ class Connection:
|
||||
configuration's ``database`` settings
|
||||
"""
|
||||
|
||||
dbconf = bigchaindb.config['database']
|
||||
dbconf = corechaindb.config['database']
|
||||
|
||||
self.host = host or dbconf['host']
|
||||
self.port = port or dbconf['port']
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from bigchaindb.exceptions import BigchainDBError
|
||||
from corechaindb.exceptions import BigchainDBError
|
||||
|
||||
|
||||
class BackendError(BigchainDBError):
|
@ -6,7 +6,7 @@
|
||||
"""MongoDB backend implementation.
|
||||
|
||||
Contains a MongoDB-specific implementation of the
|
||||
:mod:`~bigchaindb.backend.schema` and :mod:`~bigchaindb.backend.query` interfaces.
|
||||
:mod:`~corechaindb.backend.schema` and :mod:`~corechaindb.backend.query` interfaces.
|
||||
|
||||
You can specify BigchainDB to use MongoDB as its database backend by either
|
||||
setting ``database.backend`` to ``'localmongodb'`` in your configuration file, or
|
||||
@ -16,13 +16,13 @@ setting the ``BIGCHAINDB_DATABASE_BACKEND`` environment variable to
|
||||
MongoDB is the default database backend for BigchainDB.
|
||||
|
||||
If configured to use MongoDB, BigchainDB will automatically return instances
|
||||
of :class:`~bigchaindb.backend.localmongodb.LocalMongoDBConnection` for
|
||||
:func:`~bigchaindb.backend.connection.connect` and dispatch calls of the
|
||||
of :class:`~corechaindb.backend.localmongodb.LocalMongoDBConnection` for
|
||||
:func:`~corechaindb.backend.connection.connect` and dispatch calls of the
|
||||
generic backend interfaces to the implementations in this module.
|
||||
"""
|
||||
|
||||
# Register the single dispatched modules on import.
|
||||
from bigchaindb.backend.localmongodb import schema, query # noqa
|
||||
from corechaindb.backend.localmongodb import schema, query # noqa
|
||||
|
||||
# MongoDBConnection should always be accessed via
|
||||
# ``bigchaindb.backend.connect()``.
|
||||
# ``corechaindb.backend.connect()``.
|
@ -8,13 +8,13 @@ from ssl import CERT_REQUIRED
|
||||
|
||||
import pymongo
|
||||
|
||||
from bigchaindb.backend.connection import Connection
|
||||
from bigchaindb.backend.exceptions import (DuplicateKeyError,
|
||||
from corechaindb.backend.connection import Connection
|
||||
from corechaindb.backend.exceptions import (DuplicateKeyError,
|
||||
OperationError,
|
||||
ConnectionError)
|
||||
from bigchaindb.backend.utils import get_bigchaindb_config_value
|
||||
from bigchaindb.common.exceptions import ConfigurationError
|
||||
from bigchaindb.utils import Lazy
|
||||
from corechaindb.backend.utils import get_corechaindb_config_value
|
||||
from corechaindb.common.exceptions import ConfigurationError
|
||||
from corechaindb.utils import Lazy
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -34,15 +34,15 @@ class LocalMongoDBConnection(Connection):
|
||||
"""
|
||||
|
||||
super().__init__(**kwargs)
|
||||
self.replicaset = replicaset or get_bigchaindb_config_value('replicaset')
|
||||
self.ssl = ssl if ssl is not None else get_bigchaindb_config_value('ssl', False)
|
||||
self.login = login or get_bigchaindb_config_value('login')
|
||||
self.password = password or get_bigchaindb_config_value('password')
|
||||
self.ca_cert = ca_cert or get_bigchaindb_config_value('ca_cert')
|
||||
self.certfile = certfile or get_bigchaindb_config_value('certfile')
|
||||
self.keyfile = keyfile or get_bigchaindb_config_value('keyfile')
|
||||
self.keyfile_passphrase = keyfile_passphrase or get_bigchaindb_config_value('keyfile_passphrase')
|
||||
self.crlfile = crlfile or get_bigchaindb_config_value('crlfile')
|
||||
self.replicaset = replicaset or get_corechaindb_config_value('replicaset')
|
||||
self.ssl = ssl if ssl is not None else get_corechaindb_config_value('ssl', False)
|
||||
self.login = login or get_corechaindb_config_value('login')
|
||||
self.password = password or get_corechaindb_config_value('password')
|
||||
self.ca_cert = ca_cert or get_corechaindb_config_value('ca_cert')
|
||||
self.certfile = certfile or get_corechaindb_config_value('certfile')
|
||||
self.keyfile = keyfile or get_corechaindb_config_value('keyfile')
|
||||
self.keyfile_passphrase = keyfile_passphrase or get_corechaindb_config_value('keyfile_passphrase')
|
||||
self.crlfile = crlfile or get_corechaindb_config_value('crlfile')
|
||||
|
||||
@property
|
||||
def db(self):
|
@ -7,11 +7,11 @@
|
||||
|
||||
from pymongo import DESCENDING
|
||||
|
||||
from bigchaindb import backend
|
||||
from bigchaindb.backend.exceptions import DuplicateKeyError
|
||||
from bigchaindb.backend.utils import module_dispatch_registrar
|
||||
from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
from bigchaindb.common.transaction import Transaction
|
||||
from corechaindb import backend
|
||||
from corechaindb.backend.exceptions import DuplicateKeyError
|
||||
from corechaindb.backend.utils import module_dispatch_registrar
|
||||
from corechaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
from corechaindb.common.transaction import Transaction
|
||||
|
||||
register_query = module_dispatch_registrar(backend.query)
|
||||
|
@ -10,9 +10,9 @@ import logging
|
||||
from pymongo import ASCENDING, DESCENDING, TEXT
|
||||
from pymongo.errors import CollectionInvalid
|
||||
|
||||
from bigchaindb import backend
|
||||
from bigchaindb.backend.utils import module_dispatch_registrar
|
||||
from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
from corechaindb import backend
|
||||
from corechaindb.backend.utils import module_dispatch_registrar
|
||||
from corechaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
@ -7,7 +7,7 @@
|
||||
|
||||
from functools import singledispatch
|
||||
|
||||
from bigchaindb.backend.exceptions import OperationError
|
||||
from corechaindb.backend.exceptions import OperationError
|
||||
|
||||
|
||||
@singledispatch
|
@ -8,10 +8,10 @@
|
||||
from functools import singledispatch
|
||||
import logging
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.backend.connection import connect
|
||||
from bigchaindb.common.exceptions import ValidationError
|
||||
from bigchaindb.common.utils import validate_all_values_for_key_in_obj, validate_all_values_for_key_in_list
|
||||
import corechaindb
|
||||
from corechaindb.backend.connection import connect
|
||||
from corechaindb.common.exceptions import ValidationError
|
||||
from corechaindb.common.utils import validate_all_values_for_key_in_obj, validate_all_values_for_key_in_list
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -70,7 +70,7 @@ def init_database(connection=None, dbname=None):
|
||||
and supporting indexes.
|
||||
|
||||
Args:
|
||||
connection (:class:`~bigchaindb.backend.connection.Connection`): an
|
||||
connection (:class:`~corechaindb.backend.connection.Connection`): an
|
||||
existing connection to use to initialize the database.
|
||||
Creates one if not given.
|
||||
dbname (str): the name of the database to create.
|
||||
@ -79,7 +79,7 @@ def init_database(connection=None, dbname=None):
|
||||
"""
|
||||
|
||||
connection = connection or connect()
|
||||
dbname = dbname or bigchaindb.config['database']['name']
|
||||
dbname = dbname or corechaindb.config['database']['name']
|
||||
|
||||
create_database(connection, dbname)
|
||||
create_tables(connection, dbname)
|
||||
@ -97,7 +97,7 @@ def validate_language_key(obj, key):
|
||||
Raises:
|
||||
ValidationError: will raise exception in case language is not valid.
|
||||
"""
|
||||
backend = bigchaindb.config['database']['backend']
|
||||
backend = corechaindb.config['database']['backend']
|
||||
|
||||
if backend == 'localmongodb':
|
||||
data = obj.get(key, {})
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import bigchaindb
|
||||
import corechaindb
|
||||
|
||||
|
||||
class ModuleDispatchRegistrationError(Exception):
|
||||
@ -31,9 +31,9 @@ def module_dispatch_registrar(module):
|
||||
return dispatch_wrapper
|
||||
|
||||
|
||||
def get_bigchaindb_config_value(key, default_value=None):
|
||||
return bigchaindb.config['database'].get(key, default_value)
|
||||
def get_corechaindb_config_value(key, default_value=None):
|
||||
return corechaindb.config['database'].get(key, default_value)
|
||||
|
||||
|
||||
def get_bigchaindb_config_value_or_key_error(key):
|
||||
return bigchaindb.config['database'][key]
|
||||
def get_corechaindb_config_value_or_key_error(key):
|
||||
return corechaindb.config['database'][key]
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Implementation of the `bigchaindb` command,
|
||||
"""Implementation of the `corechaindb` command,
|
||||
the command-line interface (CLI) for BigchainDB Server.
|
||||
"""
|
||||
|
||||
@ -14,24 +14,24 @@ import copy
|
||||
import json
|
||||
import sys
|
||||
|
||||
from bigchaindb.core import rollback
|
||||
from bigchaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from bigchaindb.utils import load_node_key
|
||||
from bigchaindb.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||
from bigchaindb.common.exceptions import (DatabaseDoesNotExist,
|
||||
from corechaindb.core import rollback
|
||||
from corechaindb.migrations.chain_migration_election import ChainMigrationElection
|
||||
from corechaindb.utils import load_node_key
|
||||
from corechaindb.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||
from corechaindb.common.exceptions import (DatabaseDoesNotExist,
|
||||
ValidationError)
|
||||
from bigchaindb.elections.vote import Vote
|
||||
import bigchaindb
|
||||
from bigchaindb import (backend, ValidatorElection,
|
||||
from corechaindb.elections.vote import Vote
|
||||
import corechaindb
|
||||
from corechaindb import (backend, ValidatorElection,
|
||||
BigchainDB)
|
||||
from bigchaindb.backend import schema
|
||||
from bigchaindb.commands import utils
|
||||
from bigchaindb.commands.utils import (configure_bigchaindb,
|
||||
from corechaindb.backend import schema
|
||||
from corechaindb.commands import utils
|
||||
from corechaindb.commands.utils import (configure_corechaindb,
|
||||
input_on_stderr)
|
||||
from bigchaindb.log import setup_logging
|
||||
from bigchaindb.tendermint_utils import public_key_from_base64
|
||||
from bigchaindb.commands.election_types import elections
|
||||
from bigchaindb.version import __tm_supported_versions__
|
||||
from corechaindb.log import setup_logging
|
||||
from corechaindb.tendermint_utils import public_key_from_base64
|
||||
from corechaindb.commands.election_types import elections
|
||||
from corechaindb.version import __tm_supported_versions__
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -43,21 +43,21 @@ logger = logging.getLogger(__name__)
|
||||
# should be printed to stderr.
|
||||
|
||||
|
||||
@configure_bigchaindb
|
||||
@configure_corechaindb
|
||||
def run_show_config(args):
|
||||
"""Show the current configuration"""
|
||||
# TODO Proposal: remove the "hidden" configuration. Only show config. If
|
||||
# the system needs to be configured, then display information on how to
|
||||
# configure the system.
|
||||
config = copy.deepcopy(bigchaindb.config)
|
||||
config = copy.deepcopy(corechaindb.config)
|
||||
del config['CONFIGURED']
|
||||
print(json.dumps(config, indent=4, sort_keys=True))
|
||||
|
||||
|
||||
@configure_bigchaindb
|
||||
@configure_corechaindb
|
||||
def run_configure(args):
|
||||
"""Run a script to configure the current node."""
|
||||
config_path = args.config or bigchaindb.config_utils.CONFIG_DEFAULT_PATH
|
||||
config_path = args.config or corechaindb.config_utils.CONFIG_DEFAULT_PATH
|
||||
|
||||
config_file_exists = False
|
||||
# if the config path is `-` then it's stdout
|
||||
@ -70,13 +70,13 @@ def run_configure(args):
|
||||
if want != 'y':
|
||||
return
|
||||
|
||||
conf = copy.deepcopy(bigchaindb.config)
|
||||
conf = copy.deepcopy(corechaindb.config)
|
||||
|
||||
# select the correct config defaults based on the backend
|
||||
print('Generating default configuration for backend {}'
|
||||
.format(args.backend), file=sys.stderr)
|
||||
database_keys = bigchaindb._database_keys_map[args.backend]
|
||||
conf['database'] = bigchaindb._database_map[args.backend]
|
||||
database_keys = corechaindb._database_keys_map[args.backend]
|
||||
conf['database'] = corechaindb._database_map[args.backend]
|
||||
|
||||
if not args.yes:
|
||||
for key in ('bind', ):
|
||||
@ -96,14 +96,14 @@ def run_configure(args):
|
||||
conf['tendermint'][key] = input_on_stderr('Tendermint {}? (default `{}`)'.format(key, val), val)
|
||||
|
||||
if config_path != '-':
|
||||
bigchaindb.config_utils.write_config(conf, config_path)
|
||||
corechaindb.config_utils.write_config(conf, config_path)
|
||||
else:
|
||||
print(json.dumps(conf, indent=4, sort_keys=True))
|
||||
print('Configuration written to {}'.format(config_path), file=sys.stderr)
|
||||
print('Ready to go!', file=sys.stderr)
|
||||
|
||||
|
||||
@configure_bigchaindb
|
||||
@configure_corechaindb
|
||||
def run_election(args):
|
||||
"""Initiate and manage elections"""
|
||||
|
||||
@ -241,21 +241,21 @@ def run_election_show(args, bigchain):
|
||||
|
||||
|
||||
def _run_init():
|
||||
bdb = bigchaindb.BigchainDB()
|
||||
bdb = corechaindb.BigchainDB()
|
||||
|
||||
schema.init_database(connection=bdb.connection)
|
||||
|
||||
|
||||
@configure_bigchaindb
|
||||
@configure_corechaindb
|
||||
def run_init(args):
|
||||
"""Initialize the database"""
|
||||
_run_init()
|
||||
|
||||
|
||||
@configure_bigchaindb
|
||||
@configure_corechaindb
|
||||
def run_drop(args):
|
||||
"""Drop the database"""
|
||||
dbname = bigchaindb.config['database']['name']
|
||||
dbname = corechaindb.config['database']['name']
|
||||
|
||||
if not args.yes:
|
||||
response = input_on_stderr('Do you want to drop `{}` database? [y/n]: '.format(dbname))
|
||||
@ -273,22 +273,22 @@ def run_recover(b):
|
||||
rollback(b)
|
||||
|
||||
|
||||
@configure_bigchaindb
|
||||
@configure_corechaindb
|
||||
def run_start(args):
|
||||
"""Start the processes to run the node"""
|
||||
|
||||
# Configure Logging
|
||||
setup_logging()
|
||||
|
||||
logger.info('BigchainDB Version %s', bigchaindb.__version__)
|
||||
run_recover(bigchaindb.lib.BigchainDB())
|
||||
logger.info('BigchainDB Version %s', corechaindb.__version__)
|
||||
run_recover(corechaindb.lib.BigchainDB())
|
||||
|
||||
if not args.skip_initialize_database:
|
||||
logger.info('Initializing database')
|
||||
_run_init()
|
||||
|
||||
logger.info('Starting BigchainDB main process.')
|
||||
from bigchaindb.start import start
|
||||
from corechaindb.start import start
|
||||
start(args)
|
||||
|
||||
|
@ -13,14 +13,14 @@ import functools
|
||||
import multiprocessing as mp
|
||||
import sys
|
||||
|
||||
import bigchaindb
|
||||
import bigchaindb.config_utils
|
||||
from bigchaindb.version import __version__
|
||||
import corechaindb
|
||||
import corechaindb.config_utils
|
||||
from corechaindb.version import __version__
|
||||
|
||||
|
||||
def configure_bigchaindb(command):
|
||||
def configure_corechaindb(command):
|
||||
"""Decorator to be used by command line functions, such that the
|
||||
configuration of bigchaindb is performed before the execution of
|
||||
configuration of corechaindb is performed before the execution of
|
||||
the command.
|
||||
|
||||
Args:
|
||||
@ -44,7 +44,7 @@ def configure_bigchaindb(command):
|
||||
}
|
||||
except AttributeError:
|
||||
pass
|
||||
bigchaindb.config_utils.autoconfigure(
|
||||
corechaindb.config_utils.autoconfigure(
|
||||
filename=args.config, config=config_from_cmdline, force=True)
|
||||
command(args)
|
||||
|
||||
@ -138,7 +138,7 @@ def start(parser, argv, scope):
|
||||
return func(args)
|
||||
|
||||
|
||||
base_parser = argparse.ArgumentParser(add_help=False, prog='bigchaindb')
|
||||
base_parser = argparse.ArgumentParser(add_help=False, prog='corechaindb')
|
||||
|
||||
base_parser.add_argument('-c', '--config',
|
||||
help='Specify the location of the configuration file '
|
@ -26,10 +26,10 @@ def generate_key_pair():
|
||||
"""Generates a cryptographic key pair.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.crypto.CryptoKeypair`: A
|
||||
:class:`~corechaindb.common.crypto.CryptoKeypair`: A
|
||||
:obj:`collections.namedtuple` with named fields
|
||||
:attr:`~bigchaindb.common.crypto.CryptoKeypair.private_key` and
|
||||
:attr:`~bigchaindb.common.crypto.CryptoKeypair.public_key`.
|
||||
:attr:`~corechaindb.common.crypto.CryptoKeypair.private_key` and
|
||||
:attr:`~corechaindb.common.crypto.CryptoKeypair.public_key`.
|
||||
|
||||
"""
|
||||
# TODO FOR CC: Adjust interface so that this function becomes unnecessary
|
@ -3,9 +3,9 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
"""Custom exceptions used in the `bigchaindb` package.
|
||||
"""Custom exceptions used in the `corechaindb` package.
|
||||
"""
|
||||
from bigchaindb.exceptions import BigchainDBError
|
||||
from corechaindb.exceptions import BigchainDBError
|
||||
|
||||
|
||||
class ConfigurationError(BigchainDBError):
|
@ -20,7 +20,7 @@ The aim is to provide:
|
||||
## Sources
|
||||
|
||||
The files defining the JSON Schema for transactions (`transaction_*.yaml`)
|
||||
are based on the [BigchainDB Transactions Specs](https://github.com/bigchaindb/BEPs/tree/master/tx-specs).
|
||||
are based on the [BigchainDB Transactions Specs](https://github.com/corechaindb/BEPs/tree/master/tx-specs).
|
||||
If you want to add a new transaction version,
|
||||
you must write a spec for it first.
|
||||
(You can't change the JSON Schema files for old versions.
|
||||
@ -31,7 +31,7 @@ There used to be a file defining the JSON Schema for votes, named `vote.yaml`.
|
||||
It was used by BigchainDB version 1.3.0 and earlier.
|
||||
If you want a copy of the latest `vote.yaml` file,
|
||||
then you can get it from the version 1.3.0 release on GitHub, at
|
||||
[https://github.com/bigchaindb/bigchaindb/blob/v1.3.0/bigchaindb/common/schema/vote.yaml](https://github.com/bigchaindb/bigchaindb/blob/v1.3.0/bigchaindb/common/schema/vote.yaml).
|
||||
[https://github.com/corechaindb/corechaindb/blob/v1.3.0/corechaindb/common/schema/vote.yaml](https://github.com/corechaindb/corechaindb/blob/v1.3.0/corechaindb/common/schema/vote.yaml).
|
||||
|
||||
## Learn about JSON Schema
|
||||
|
@ -11,7 +11,7 @@ import jsonschema
|
||||
import yaml
|
||||
import rapidjson
|
||||
|
||||
from bigchaindb.common.exceptions import SchemaValidationError
|
||||
from corechaindb.common.exceptions import SchemaValidationError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
@ -25,13 +25,13 @@ try:
|
||||
except ImportError:
|
||||
from sha3 import sha3_256
|
||||
|
||||
from bigchaindb.common.crypto import PrivateKey, hash_data
|
||||
from bigchaindb.common.exceptions import (KeypairMismatchException,
|
||||
from corechaindb.common.crypto import PrivateKey, hash_data
|
||||
from corechaindb.common.exceptions import (KeypairMismatchException,
|
||||
InputDoesNotExist, DoubleSpend,
|
||||
InvalidHash, InvalidSignature,
|
||||
AmountError, AssetIdMismatch,
|
||||
ThresholdTooDeep)
|
||||
from bigchaindb.common.utils import serialize
|
||||
from corechaindb.common.utils import serialize
|
||||
from .memoize import memoize_from_dict, memoize_to_dict
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ class Input(object):
|
||||
to be signed with a private key.
|
||||
owners_before (:obj:`list` of :obj:`str`): A list of owners after a
|
||||
Transaction was confirmed.
|
||||
fulfills (:class:`~bigchaindb.common.transaction. TransactionLink`,
|
||||
fulfills (:class:`~corechaindb.common.transaction. TransactionLink`,
|
||||
optional): A link representing the input of a `TRANSFER`
|
||||
Transaction.
|
||||
"""
|
||||
@ -71,7 +71,7 @@ class Input(object):
|
||||
Fulfillment to be signed with a private key.
|
||||
owners_before (:obj:`list` of :obj:`str`): A list of owners
|
||||
after a Transaction was confirmed.
|
||||
fulfills (:class:`~bigchaindb.common.transaction.
|
||||
fulfills (:class:`~corechaindb.common.transaction.
|
||||
TransactionLink`, optional): A link representing the input
|
||||
of a `TRANSFER` Transaction.
|
||||
"""
|
||||
@ -141,7 +141,7 @@ class Input(object):
|
||||
data (dict): The Input to be transformed.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.Input`
|
||||
:class:`~corechaindb.common.transaction.Input`
|
||||
|
||||
Raises:
|
||||
InvalidSignature: If an Input's URI couldn't be parsed.
|
||||
@ -257,7 +257,7 @@ class TransactionLink(object):
|
||||
link (dict): The link to be transformed.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.TransactionLink`
|
||||
:class:`~corechaindb.common.transaction.TransactionLink`
|
||||
"""
|
||||
try:
|
||||
return cls(link['transaction_id'], link['output_index'])
|
||||
@ -468,7 +468,7 @@ class Output(object):
|
||||
data (dict): The dict to be transformed.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.Output`
|
||||
:class:`~corechaindb.common.transaction.Output`
|
||||
"""
|
||||
try:
|
||||
fulfillment = _fulfillment_from_details(data['condition']['details'])
|
||||
@ -491,10 +491,10 @@ class Transaction(object):
|
||||
|
||||
Attributes:
|
||||
operation (str): Defines the operation of the Transaction.
|
||||
inputs (:obj:`list` of :class:`~bigchaindb.common.
|
||||
inputs (:obj:`list` of :class:`~corechaindb.common.
|
||||
transaction.Input`, optional): Define the assets to
|
||||
spend.
|
||||
outputs (:obj:`list` of :class:`~bigchaindb.common.
|
||||
outputs (:obj:`list` of :class:`~corechaindb.common.
|
||||
transaction.Output`, optional): Define the assets to lock.
|
||||
asset (dict): Asset payload for this Transaction. ``CREATE``
|
||||
Transactions require a dict with a ``data``
|
||||
@ -521,9 +521,9 @@ class Transaction(object):
|
||||
Args:
|
||||
operation (str): Defines the operation of the Transaction.
|
||||
asset (dict): Asset payload for this Transaction.
|
||||
inputs (:obj:`list` of :class:`~bigchaindb.common.
|
||||
inputs (:obj:`list` of :class:`~corechaindb.common.
|
||||
transaction.Input`, optional): Define the assets to
|
||||
outputs (:obj:`list` of :class:`~bigchaindb.common.
|
||||
outputs (:obj:`list` of :class:`~corechaindb.common.
|
||||
transaction.Output`, optional): Define the assets to
|
||||
lock.
|
||||
metadata (dict): Metadata to be stored along with the
|
||||
@ -660,7 +660,7 @@ class Transaction(object):
|
||||
be created in this Transaction.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.Transaction`
|
||||
:class:`~corechaindb.common.transaction.Transaction`
|
||||
"""
|
||||
|
||||
(inputs, outputs) = cls.validate_create(tx_signers, recipients, asset, metadata)
|
||||
@ -716,7 +716,7 @@ class Transaction(object):
|
||||
weight respectively. `inp2` is owned completely by `d`.
|
||||
|
||||
Args:
|
||||
inputs (:obj:`list` of :class:`~bigchaindb.common.transaction.
|
||||
inputs (:obj:`list` of :class:`~corechaindb.common.transaction.
|
||||
Input`): Converted `Output`s, intended to
|
||||
be used as inputs in the transfer to generate.
|
||||
recipients (:obj:`list` of :obj:`tuple`): A list of
|
||||
@ -728,7 +728,7 @@ class Transaction(object):
|
||||
Transaction.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.Transaction`
|
||||
:class:`~corechaindb.common.transaction.Transaction`
|
||||
"""
|
||||
(inputs, outputs) = cls.validate_transfer(inputs, recipients, asset_id, metadata)
|
||||
return cls(cls.TRANSFER, {'id': asset_id}, inputs, outputs, metadata)
|
||||
@ -757,7 +757,7 @@ class Transaction(object):
|
||||
outputs should be returned as inputs.
|
||||
|
||||
Returns:
|
||||
:obj:`list` of :class:`~bigchaindb.common.transaction.
|
||||
:obj:`list` of :class:`~corechaindb.common.transaction.
|
||||
Input`
|
||||
"""
|
||||
# NOTE: If no indices are passed, we just assume to take all outputs
|
||||
@ -774,7 +774,7 @@ class Transaction(object):
|
||||
"""Adds an input to a Transaction's list of inputs.
|
||||
|
||||
Args:
|
||||
input_ (:class:`~bigchaindb.common.transaction.
|
||||
input_ (:class:`~corechaindb.common.transaction.
|
||||
Input`): An Input to be added to the Transaction.
|
||||
"""
|
||||
if not isinstance(input_, Input):
|
||||
@ -785,7 +785,7 @@ class Transaction(object):
|
||||
"""Adds an output to a Transaction's list of outputs.
|
||||
|
||||
Args:
|
||||
output (:class:`~bigchaindb.common.transaction.
|
||||
output (:class:`~corechaindb.common.transaction.
|
||||
Output`): An Output to be added to the
|
||||
Transaction.
|
||||
"""
|
||||
@ -811,7 +811,7 @@ class Transaction(object):
|
||||
Transaction.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.Transaction`
|
||||
:class:`~corechaindb.common.transaction.Transaction`
|
||||
"""
|
||||
# TODO: Singing should be possible with at least one of all private
|
||||
# keys supplied to this method.
|
||||
@ -857,7 +857,7 @@ class Transaction(object):
|
||||
- ThresholdSha256.
|
||||
|
||||
Args:
|
||||
input_ (:class:`~bigchaindb.common.transaction.
|
||||
input_ (:class:`~corechaindb.common.transaction.
|
||||
Input`) The Input to be signed.
|
||||
message (str): The message to be signed
|
||||
key_pairs (dict): The keys to sign the Transaction with.
|
||||
@ -878,7 +878,7 @@ class Transaction(object):
|
||||
"""Signs a Ed25519Fulfillment.
|
||||
|
||||
Args:
|
||||
input_ (:class:`~bigchaindb.common.transaction.
|
||||
input_ (:class:`~corechaindb.common.transaction.
|
||||
Input`) The input to be signed.
|
||||
message (str): The message to be signed
|
||||
key_pairs (dict): The keys to sign the Transaction with.
|
||||
@ -910,7 +910,7 @@ class Transaction(object):
|
||||
"""Signs a ThresholdSha256.
|
||||
|
||||
Args:
|
||||
input_ (:class:`~bigchaindb.common.transaction.
|
||||
input_ (:class:`~corechaindb.common.transaction.
|
||||
Input`) The Input to be signed.
|
||||
message (str): The message to be signed
|
||||
key_pairs (dict): The keys to sign the Transaction with.
|
||||
@ -962,7 +962,7 @@ class Transaction(object):
|
||||
evaluate parts of the validation-checks to `True`.
|
||||
|
||||
Args:
|
||||
outputs (:obj:`list` of :class:`~bigchaindb.common.
|
||||
outputs (:obj:`list` of :class:`~corechaindb.common.
|
||||
transaction.Output`): A list of Outputs to check the
|
||||
Inputs against.
|
||||
|
||||
@ -1025,7 +1025,7 @@ class Transaction(object):
|
||||
does not validate against `output_condition_uri`.
|
||||
|
||||
Args:
|
||||
input_ (:class:`~bigchaindb.common.transaction.
|
||||
input_ (:class:`~corechaindb.common.transaction.
|
||||
Input`) The Input to be signed.
|
||||
operation (str): The type of Transaction.
|
||||
message (str): The fulfillment message.
|
||||
@ -1134,7 +1134,7 @@ class Transaction(object):
|
||||
transaction are related to the same asset id.
|
||||
|
||||
Args:
|
||||
transactions (:obj:`list` of :class:`~bigchaindb.common.
|
||||
transactions (:obj:`list` of :class:`~corechaindb.common.
|
||||
transaction.Transaction`): A list of Transactions.
|
||||
Usually input Transactions that should have a matching
|
||||
asset ID.
|
||||
@ -1196,7 +1196,7 @@ class Transaction(object):
|
||||
tx_body (dict): The Transaction to be transformed.
|
||||
|
||||
Returns:
|
||||
:class:`~bigchaindb.common.transaction.Transaction`
|
||||
:class:`~corechaindb.common.transaction.Transaction`
|
||||
"""
|
||||
operation = tx.get('operation', Transaction.CREATE) if isinstance(tx, dict) else Transaction.CREATE
|
||||
cls = Transaction.resolve_class(operation)
|
||||
@ -1217,7 +1217,7 @@ class Transaction(object):
|
||||
asset from the asset table and reconstructs the transaction.
|
||||
|
||||
Args:
|
||||
bigchain (:class:`~bigchaindb.tendermint.BigchainDB`): An instance
|
||||
bigchain (:class:`~corechaindb.tendermint.BigchainDB`): An instance
|
||||
of BigchainDB used to perform database queries.
|
||||
tx_dict_list (:list:`dict` or :obj:`dict`): The transaction dict or
|
||||
list of transaction dict as returned from the database.
|
@ -7,8 +7,8 @@ import time
|
||||
import re
|
||||
import rapidjson
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.common.exceptions import ValidationError
|
||||
import corechaindb
|
||||
from corechaindb.common.exceptions import ValidationError
|
||||
|
||||
|
||||
def gen_timestamp():
|
||||
@ -72,7 +72,7 @@ def validate_txn_obj(obj_name, obj, key, validation_fun):
|
||||
Raises:
|
||||
ValidationError: `validation_fun` will raise exception on failure
|
||||
"""
|
||||
backend = bigchaindb.config['database']['backend']
|
||||
backend = corechaindb.config['database']['backend']
|
||||
|
||||
if backend == 'localmongodb':
|
||||
data = obj.get(key, {})
|
@ -12,7 +12,7 @@ determined according to the following rules:
|
||||
* Otherwise, if it's set in a local config file, then use that
|
||||
value
|
||||
* Otherwise, use the default value (contained in
|
||||
``bigchaindb.__init__``)
|
||||
``corechaindb.__init__``)
|
||||
"""
|
||||
|
||||
|
||||
@ -25,11 +25,11 @@ from functools import lru_cache
|
||||
|
||||
from pkg_resources import iter_entry_points, ResolutionError
|
||||
|
||||
from bigchaindb.common import exceptions
|
||||
from corechaindb.common import exceptions
|
||||
|
||||
import bigchaindb
|
||||
import corechaindb
|
||||
|
||||
from bigchaindb.validation import BaseValidationRules
|
||||
from corechaindb.validation import BaseValidationRules
|
||||
|
||||
# TODO: move this to a proper configuration file for logging
|
||||
logging.getLogger('requests').setLevel(logging.WARNING)
|
||||
@ -37,7 +37,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_DEFAULT_PATH = os.environ.setdefault(
|
||||
'BIGCHAINDB_CONFIG_PATH',
|
||||
os.path.join(os.path.expanduser('~'), '.bigchaindb'),
|
||||
os.path.join(os.path.expanduser('~'), '.corechaindb'),
|
||||
)
|
||||
|
||||
CONFIG_PREFIX = 'BIGCHAINDB'
|
||||
@ -180,27 +180,27 @@ def update_types(config, reference, list_sep=':'):
|
||||
|
||||
|
||||
def set_config(config):
|
||||
"""Set bigchaindb.config equal to the default config dict,
|
||||
"""Set corechaindb.config equal to the default config dict,
|
||||
then update that with whatever is in the provided config dict,
|
||||
and then set bigchaindb.config['CONFIGURED'] = True
|
||||
and then set corechaindb.config['CONFIGURED'] = True
|
||||
|
||||
Args:
|
||||
config (dict): the config dict to read for changes
|
||||
to the default config
|
||||
|
||||
Note:
|
||||
Any previous changes made to ``bigchaindb.config`` will be lost.
|
||||
Any previous changes made to ``corechaindb.config`` will be lost.
|
||||
"""
|
||||
# Deep copy the default config into bigchaindb.config
|
||||
bigchaindb.config = copy.deepcopy(bigchaindb._config)
|
||||
# Deep copy the default config into corechaindb.config
|
||||
corechaindb.config = copy.deepcopy(corechaindb._config)
|
||||
# Update the default config with whatever is in the passed config
|
||||
update(bigchaindb.config, update_types(config, bigchaindb.config))
|
||||
bigchaindb.config['CONFIGURED'] = True
|
||||
update(corechaindb.config, update_types(config, corechaindb.config))
|
||||
corechaindb.config['CONFIGURED'] = True
|
||||
|
||||
|
||||
def update_config(config):
|
||||
"""Update bigchaindb.config with whatever is in the provided config dict,
|
||||
and then set bigchaindb.config['CONFIGURED'] = True
|
||||
"""Update corechaindb.config with whatever is in the provided config dict,
|
||||
and then set corechaindb.config['CONFIGURED'] = True
|
||||
|
||||
Args:
|
||||
config (dict): the config dict to read for changes
|
||||
@ -208,8 +208,8 @@ def update_config(config):
|
||||
"""
|
||||
|
||||
# Update the default config with whatever is in the passed config
|
||||
update(bigchaindb.config, update_types(config, bigchaindb.config))
|
||||
bigchaindb.config['CONFIGURED'] = True
|
||||
update(corechaindb.config, update_types(config, corechaindb.config))
|
||||
corechaindb.config['CONFIGURED'] = True
|
||||
|
||||
|
||||
def write_config(config, filename=None):
|
||||
@ -218,7 +218,7 @@ def write_config(config, filename=None):
|
||||
Args:
|
||||
config (dict): a dictionary with the configuration to load.
|
||||
filename (str): the name of the file that will store the new configuration. Defaults to ``None``.
|
||||
If ``None``, the HOME of the current user and the string ``.bigchaindb`` will be used.
|
||||
If ``None``, the HOME of the current user and the string ``.corechaindb`` will be used.
|
||||
"""
|
||||
if not filename:
|
||||
filename = CONFIG_DEFAULT_PATH
|
||||
@ -228,7 +228,7 @@ def write_config(config, filename=None):
|
||||
|
||||
|
||||
def is_configured():
|
||||
return bool(bigchaindb.config.get('CONFIGURED'))
|
||||
return bool(corechaindb.config.get('CONFIGURED'))
|
||||
|
||||
|
||||
def autoconfigure(filename=None, config=None, force=False):
|
||||
@ -240,7 +240,7 @@ def autoconfigure(filename=None, config=None, force=False):
|
||||
return
|
||||
|
||||
# start with the current configuration
|
||||
newconfig = bigchaindb.config
|
||||
newconfig = corechaindb.config
|
||||
|
||||
# update configuration from file
|
||||
try:
|
||||
@ -255,7 +255,7 @@ def autoconfigure(filename=None, config=None, force=False):
|
||||
newconfig = env_config(newconfig)
|
||||
if config:
|
||||
newconfig = update(newconfig, config)
|
||||
set_config(newconfig) # sets bigchaindb.config
|
||||
set_config(newconfig) # sets corechaindb.config
|
||||
|
||||
|
||||
@lru_cache()
|
||||
@ -267,29 +267,29 @@ def load_validation_plugin(name=None):
|
||||
setup.py of the providing package.
|
||||
|
||||
Returns:
|
||||
an uninstantiated subclass of ``bigchaindb.validation.AbstractValidationRules``
|
||||
an uninstantiated subclass of ``corechaindb.validation.AbstractValidationRules``
|
||||
"""
|
||||
if not name:
|
||||
return BaseValidationRules
|
||||
|
||||
# TODO: This will return the first plugin with group `bigchaindb.validation`
|
||||
# TODO: This will return the first plugin with group `corechaindb.validation`
|
||||
# and name `name` in the active WorkingSet.
|
||||
# We should probably support Requirements specs in the config, e.g.
|
||||
# validation_plugin: 'my-plugin-package==0.0.1;default'
|
||||
plugin = None
|
||||
for entry_point in iter_entry_points('bigchaindb.validation', name):
|
||||
for entry_point in iter_entry_points('corechaindb.validation', name):
|
||||
plugin = entry_point.load()
|
||||
|
||||
# No matching entry_point found
|
||||
if not plugin:
|
||||
raise ResolutionError(
|
||||
'No plugin found in group `bigchaindb.validation` with name `{}`'.
|
||||
'No plugin found in group `corechaindb.validation` with name `{}`'.
|
||||
format(name))
|
||||
|
||||
# Is this strictness desireable?
|
||||
# It will probably reduce developer headaches in the wild.
|
||||
if not issubclass(plugin, (BaseValidationRules,)):
|
||||
raise TypeError('object of type "{}" does not implement `bigchaindb.'
|
||||
raise TypeError('object of type "{}" does not implement `corechaindb.'
|
||||
'validation.BaseValidationRules`'.format(type(plugin)))
|
||||
|
||||
return plugin
|
||||
@ -302,7 +302,7 @@ def load_events_plugins(names=None):
|
||||
return plugins
|
||||
|
||||
for name in names:
|
||||
for entry_point in iter_entry_points('bigchaindb.events', name):
|
||||
for entry_point in iter_entry_points('corechaindb.events', name):
|
||||
plugins.append((name, entry_point.load()))
|
||||
|
||||
return plugins
|
@ -12,15 +12,15 @@ import sys
|
||||
from abci.application import BaseApplication
|
||||
from abci import CodeTypeOk
|
||||
|
||||
from bigchaindb import BigchainDB
|
||||
from bigchaindb.elections.election import Election
|
||||
from bigchaindb.version import __tm_supported_versions__
|
||||
from bigchaindb.utils import tendermint_version_is_compatible
|
||||
from bigchaindb.tendermint_utils import (decode_transaction,
|
||||
from corechaindb import BigchainDB
|
||||
from corechaindb.elections.election import Election
|
||||
from corechaindb.version import __tm_supported_versions__
|
||||
from corechaindb.utils import tendermint_version_is_compatible
|
||||
from corechaindb.tendermint_utils import (decode_transaction,
|
||||
calculate_hash)
|
||||
from bigchaindb.lib import Block
|
||||
import bigchaindb.upsert_validator.validator_utils as vutils
|
||||
from bigchaindb.events import EventTypes, Event
|
||||
from corechaindb.lib import Block
|
||||
import corechaindb.upsert_validator.validator_utils as vutils
|
||||
from corechaindb.events import EventTypes, Event
|
||||
|
||||
|
||||
CodeTypeError = 1
|
||||
@ -34,16 +34,16 @@ class App(BaseApplication):
|
||||
transaction logic to Tendermint Core.
|
||||
"""
|
||||
|
||||
def __init__(self, abci, bigchaindb=None, events_queue=None,):
|
||||
def __init__(self, abci, corechaindb=None, events_queue=None,):
|
||||
super().__init__(abci)
|
||||
self.events_queue = events_queue
|
||||
self.bigchaindb = bigchaindb or BigchainDB()
|
||||
self.corechaindb = corechaindb or BigchainDB()
|
||||
self.block_txn_ids = []
|
||||
self.block_txn_hash = ''
|
||||
self.block_transactions = []
|
||||
self.validators = None
|
||||
self.new_height = None
|
||||
self.chain = self.bigchaindb.get_latest_abci_chain()
|
||||
self.chain = self.corechaindb.get_latest_abci_chain()
|
||||
|
||||
def log_abci_migration_error(self, chain_id, validators):
|
||||
logger.error('An ABCI chain migration is in process. '
|
||||
@ -54,7 +54,7 @@ class App(BaseApplication):
|
||||
if self.chain is None or self.chain['is_synced']:
|
||||
return
|
||||
|
||||
validators = self.bigchaindb.get_validators()
|
||||
validators = self.corechaindb.get_validators()
|
||||
self.log_abci_migration_error(self.chain['chain_id'], validators)
|
||||
sys.exit(1)
|
||||
|
||||
@ -64,7 +64,7 @@ class App(BaseApplication):
|
||||
app_hash = ''
|
||||
height = 0
|
||||
|
||||
known_chain = self.bigchaindb.get_latest_abci_chain()
|
||||
known_chain = self.corechaindb.get_latest_abci_chain()
|
||||
if known_chain is not None:
|
||||
chain_id = known_chain['chain_id']
|
||||
|
||||
@ -75,16 +75,16 @@ class App(BaseApplication):
|
||||
sys.exit(1)
|
||||
|
||||
if chain_id != genesis.chain_id:
|
||||
validators = self.bigchaindb.get_validators()
|
||||
validators = self.corechaindb.get_validators()
|
||||
self.log_abci_migration_error(chain_id, validators)
|
||||
sys.exit(1)
|
||||
|
||||
# set migration values for app hash and height
|
||||
block = self.bigchaindb.get_latest_block()
|
||||
block = self.corechaindb.get_latest_block()
|
||||
app_hash = '' if block is None else block['app_hash']
|
||||
height = 0 if block is None else block['height'] + 1
|
||||
|
||||
known_validators = self.bigchaindb.get_validators()
|
||||
known_validators = self.corechaindb.get_validators()
|
||||
validator_set = [vutils.decode_validator(v)
|
||||
for v in genesis.validators]
|
||||
|
||||
@ -94,10 +94,10 @@ class App(BaseApplication):
|
||||
sys.exit(1)
|
||||
|
||||
block = Block(app_hash=app_hash, height=height, transactions=[])
|
||||
self.bigchaindb.store_block(block._asdict())
|
||||
self.bigchaindb.store_validator_set(height + 1, validator_set)
|
||||
self.corechaindb.store_block(block._asdict())
|
||||
self.corechaindb.store_validator_set(height + 1, validator_set)
|
||||
abci_chain_height = 0 if known_chain is None else known_chain['height']
|
||||
self.bigchaindb.store_abci_chain(abci_chain_height,
|
||||
self.corechaindb.store_abci_chain(abci_chain_height,
|
||||
genesis.chain_id, True)
|
||||
self.chain = {'height': abci_chain_height, 'is_synced': True,
|
||||
'chain_id': genesis.chain_id}
|
||||
@ -117,7 +117,7 @@ class App(BaseApplication):
|
||||
logger.info(f"Tendermint version: {request.version}")
|
||||
|
||||
r = self.abci.ResponseInfo()
|
||||
block = self.bigchaindb.get_latest_block()
|
||||
block = self.corechaindb.get_latest_block()
|
||||
if block:
|
||||
chain_shift = 0 if self.chain is None else self.chain['height']
|
||||
r.last_block_height = block['height'] - chain_shift
|
||||
@ -139,7 +139,7 @@ class App(BaseApplication):
|
||||
|
||||
logger.debug('check_tx: %s', raw_transaction)
|
||||
transaction = decode_transaction(raw_transaction)
|
||||
if self.bigchaindb.is_valid_transaction(transaction):
|
||||
if self.corechaindb.is_valid_transaction(transaction):
|
||||
logger.debug('check_tx: VALID')
|
||||
return self.abci.ResponseCheckTx(code=CodeTypeOk)
|
||||
else:
|
||||
@ -173,7 +173,7 @@ class App(BaseApplication):
|
||||
self.abort_if_abci_chain_is_not_synced()
|
||||
|
||||
logger.debug('deliver_tx: %s', raw_transaction)
|
||||
transaction = self.bigchaindb.is_valid_transaction(
|
||||
transaction = self.corechaindb.is_valid_transaction(
|
||||
decode_transaction(raw_transaction), self.block_transactions)
|
||||
|
||||
if not transaction:
|
||||
@ -205,17 +205,17 @@ class App(BaseApplication):
|
||||
logger.debug(f'Updating pre-commit state: {self.new_height}')
|
||||
pre_commit_state = dict(height=self.new_height,
|
||||
transactions=self.block_txn_ids)
|
||||
self.bigchaindb.store_pre_commit_state(pre_commit_state)
|
||||
self.corechaindb.store_pre_commit_state(pre_commit_state)
|
||||
|
||||
block_txn_hash = calculate_hash(self.block_txn_ids)
|
||||
block = self.bigchaindb.get_latest_block()
|
||||
block = self.corechaindb.get_latest_block()
|
||||
|
||||
if self.block_txn_ids:
|
||||
self.block_txn_hash = calculate_hash([block['app_hash'], block_txn_hash])
|
||||
else:
|
||||
self.block_txn_hash = block['app_hash']
|
||||
|
||||
validator_update = Election.process_block(self.bigchaindb,
|
||||
validator_update = Election.process_block(self.corechaindb,
|
||||
self.new_height,
|
||||
self.block_transactions)
|
||||
|
||||
@ -230,14 +230,14 @@ class App(BaseApplication):
|
||||
|
||||
# register a new block only when new transactions are received
|
||||
if self.block_txn_ids:
|
||||
self.bigchaindb.store_bulk_transactions(self.block_transactions)
|
||||
self.corechaindb.store_bulk_transactions(self.block_transactions)
|
||||
|
||||
block = Block(app_hash=self.block_txn_hash,
|
||||
height=self.new_height,
|
||||
transactions=self.block_txn_ids)
|
||||
# NOTE: storing the block should be the last operation during commit
|
||||
# this effects crash recovery. Refer BEP#8 for details
|
||||
self.bigchaindb.store_block(block._asdict())
|
||||
self.corechaindb.store_block(block._asdict())
|
||||
|
||||
logger.debug('Commit-ing new block with hash: apphash=%s ,'
|
||||
'height=%s, txn ids=%s', data, self.new_height,
|
@ -7,17 +7,17 @@ from collections import OrderedDict
|
||||
import base58
|
||||
from uuid import uuid4
|
||||
|
||||
from bigchaindb import backend
|
||||
from bigchaindb.elections.vote import Vote
|
||||
from bigchaindb.common.exceptions import (InvalidSignature,
|
||||
from corechaindb import backend
|
||||
from corechaindb.elections.vote import Vote
|
||||
from corechaindb.common.exceptions import (InvalidSignature,
|
||||
MultipleInputsError,
|
||||
InvalidProposer,
|
||||
UnequalValidatorSet,
|
||||
DuplicateTransaction)
|
||||
from bigchaindb.tendermint_utils import key_from_base64, public_key_to_base64
|
||||
from bigchaindb.common.crypto import (public_key_from_ed25519_key)
|
||||
from bigchaindb.common.transaction import Transaction
|
||||
from bigchaindb.common.schema import (_validate_schema,
|
||||
from corechaindb.tendermint_utils import key_from_base64, public_key_to_base64
|
||||
from corechaindb.common.crypto import (public_key_from_ed25519_key)
|
||||
from corechaindb.common.transaction import Transaction
|
||||
from corechaindb.common.schema import (_validate_schema,
|
||||
TX_SCHEMA_COMMON,
|
||||
TX_SCHEMA_CREATE)
|
||||
|
||||
@ -102,7 +102,7 @@ class Election(Transaction):
|
||||
allocated according to the voting power of each validator node.
|
||||
|
||||
Args:
|
||||
:param bigchain: (BigchainDB) an instantiated bigchaindb.lib.BigchainDB object.
|
||||
:param bigchain: (BigchainDB) an instantiated corechaindb.lib.BigchainDB object.
|
||||
:param current_transactions: (list) A list of transactions to be validated along with the election
|
||||
|
||||
Returns:
|
@ -3,8 +3,8 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from bigchaindb.common.transaction import Transaction
|
||||
from bigchaindb.common.schema import (_validate_schema,
|
||||
from corechaindb.common.transaction import Transaction
|
||||
from corechaindb.common.schema import (_validate_schema,
|
||||
TX_SCHEMA_COMMON,
|
||||
TX_SCHEMA_TRANSFER,
|
||||
TX_SCHEMA_VOTE)
|
||||
@ -25,10 +25,10 @@ class Vote(Transaction):
|
||||
NOTE: There are no additional validity conditions on casting votes i.e.
|
||||
a vote is just a valid TRANFER transaction
|
||||
|
||||
For more details refer BEP-21: https://github.com/bigchaindb/BEPs/tree/master/21
|
||||
For more details refer BEP-21: https://github.com/corechaindb/BEPs/tree/master/21
|
||||
|
||||
Args:
|
||||
bigchain (BigchainDB): an instantiated bigchaindb.lib.BigchainDB object.
|
||||
bigchain (BigchainDB): an instantiated corechaindb.lib.BigchainDB object.
|
||||
|
||||
Returns:
|
||||
Vote: a Vote object
|
@ -34,7 +34,7 @@ class Event:
|
||||
|
||||
Args:
|
||||
event_type (int): the type of the event, see
|
||||
:class:`~bigchaindb.events.EventTypes`
|
||||
:class:`~corechaindb.events.EventTypes`
|
||||
event_data (obj): the data of the event.
|
||||
"""
|
||||
|
||||
@ -88,7 +88,7 @@ class Exchange:
|
||||
"""Given an event, send it to all the subscribers.
|
||||
|
||||
Args
|
||||
event (:class:`~bigchaindb.events.EventTypes`): the event to
|
||||
event (:class:`~corechaindb.events.EventTypes`): the event to
|
||||
dispatch to all the subscribers.
|
||||
"""
|
||||
|
@ -3,9 +3,9 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from bigchaindb.utils import condition_details_has_owner
|
||||
from bigchaindb.backend import query
|
||||
from bigchaindb.common.transaction import TransactionLink
|
||||
from corechaindb.utils import condition_details_has_owner
|
||||
from corechaindb.backend import query
|
||||
from corechaindb.common.transaction import TransactionLink
|
||||
|
||||
|
||||
class FastQuery():
|
@ -21,18 +21,18 @@ except ImportError:
|
||||
|
||||
import requests
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb import backend, config_utils, fastquery
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.common.exceptions import (SchemaValidationError,
|
||||
import corechaindb
|
||||
from corechaindb import backend, config_utils, fastquery
|
||||
from corechaindb.models import Transaction
|
||||
from corechaindb.common.exceptions import (SchemaValidationError,
|
||||
ValidationError,
|
||||
DoubleSpend)
|
||||
from bigchaindb.common.transaction_mode_types import (BROADCAST_TX_COMMIT,
|
||||
from corechaindb.common.transaction_mode_types import (BROADCAST_TX_COMMIT,
|
||||
BROADCAST_TX_ASYNC,
|
||||
BROADCAST_TX_SYNC)
|
||||
from bigchaindb.tendermint_utils import encode_transaction, merkleroot
|
||||
from bigchaindb import exceptions as core_exceptions
|
||||
from bigchaindb.validation import BaseValidationRules
|
||||
from corechaindb.tendermint_utils import encode_transaction, merkleroot
|
||||
from corechaindb import exceptions as core_exceptions
|
||||
from corechaindb.validation import BaseValidationRules
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -54,10 +54,10 @@ class BigchainDB(object):
|
||||
If that environment variable isn't set, then the value
|
||||
will come from the local configuration file. And if that variable
|
||||
isn't in the local configuration file, then the parameter will have
|
||||
its default value (defined in bigchaindb.__init__).
|
||||
its default value (defined in corechaindb.__init__).
|
||||
|
||||
Args:
|
||||
connection (:class:`~bigchaindb.backend.connection.Connection`):
|
||||
connection (:class:`~corechaindb.backend.connection.Connection`):
|
||||
A connection to the database.
|
||||
"""
|
||||
config_utils.autoconfigure()
|
||||
@ -65,18 +65,18 @@ class BigchainDB(object):
|
||||
self.mode_list = (BROADCAST_TX_ASYNC,
|
||||
BROADCAST_TX_SYNC,
|
||||
self.mode_commit)
|
||||
self.tendermint_host = bigchaindb.config['tendermint']['host']
|
||||
self.tendermint_port = bigchaindb.config['tendermint']['port']
|
||||
self.tendermint_host = corechaindb.config['tendermint']['host']
|
||||
self.tendermint_port = corechaindb.config['tendermint']['port']
|
||||
self.endpoint = 'http://{}:{}/'.format(self.tendermint_host, self.tendermint_port)
|
||||
|
||||
validationPlugin = bigchaindb.config.get('validation_plugin')
|
||||
validationPlugin = corechaindb.config.get('validation_plugin')
|
||||
|
||||
if validationPlugin:
|
||||
self.validation = config_utils.load_validation_plugin(validationPlugin)
|
||||
else:
|
||||
self.validation = BaseValidationRules
|
||||
|
||||
self.connection = connection if connection else backend.connect(**bigchaindb.config['database'])
|
||||
self.connection = connection if connection else backend.connect(**corechaindb.config['database'])
|
||||
|
||||
def post_transaction(self, transaction, mode):
|
||||
"""Submit a valid transaction to the mempool."""
|
||||
@ -157,7 +157,7 @@ class BigchainDB(object):
|
||||
outputs that the given ``transaction`` creates.
|
||||
|
||||
Args:
|
||||
transaction (:obj:`~bigchaindb.models.Transaction`): A new
|
||||
transaction (:obj:`~corechaindb.models.Transaction`): A new
|
||||
transaction incoming into the system for which the UTXO
|
||||
set needs to be updated.
|
||||
"""
|
@ -3,10 +3,10 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import bigchaindb
|
||||
import corechaindb
|
||||
import logging
|
||||
|
||||
from bigchaindb.common.exceptions import ConfigurationError
|
||||
from corechaindb.common.exceptions import ConfigurationError
|
||||
from logging.config import dictConfig as set_logging_config
|
||||
import os
|
||||
|
||||
@ -38,7 +38,7 @@ DEFAULT_LOGGING_CONFIG = {
|
||||
},
|
||||
'file': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': os.path.join(DEFAULT_LOG_DIR, 'bigchaindb.log'),
|
||||
'filename': os.path.join(DEFAULT_LOG_DIR, 'corechaindb.log'),
|
||||
'mode': 'w',
|
||||
'maxBytes': 209715200,
|
||||
'backupCount': 5,
|
||||
@ -47,7 +47,7 @@ DEFAULT_LOGGING_CONFIG = {
|
||||
},
|
||||
'errors': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': os.path.join(DEFAULT_LOG_DIR, 'bigchaindb-errors.log'),
|
||||
'filename': os.path.join(DEFAULT_LOG_DIR, 'corechaindb-errors.log'),
|
||||
'mode': 'w',
|
||||
'maxBytes': 209715200,
|
||||
'backupCount': 5,
|
||||
@ -78,13 +78,13 @@ def setup_logging():
|
||||
Configuration, if needed, should be applied before invoking this
|
||||
decorator, as starting the subscriber process for logging will
|
||||
configure the root logger for the child process based on the
|
||||
state of :obj:`bigchaindb.config` at the moment this decorator
|
||||
state of :obj:`corechaindb.config` at the moment this decorator
|
||||
is invoked.
|
||||
|
||||
"""
|
||||
|
||||
logging_configs = DEFAULT_LOGGING_CONFIG
|
||||
new_logging_configs = bigchaindb.config['log']
|
||||
new_logging_configs = corechaindb.config['log']
|
||||
|
||||
if 'file' in new_logging_configs:
|
||||
filename = new_logging_configs['file']
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
from bigchaindb.common.schema import TX_SCHEMA_CHAIN_MIGRATION_ELECTION
|
||||
from bigchaindb.elections.election import Election
|
||||
from corechaindb.common.schema import TX_SCHEMA_CHAIN_MIGRATION_ELECTION
|
||||
from corechaindb.elections.election import Election
|
||||
|
||||
|
||||
class ChainMigrationElection(Election):
|
||||
@ -11,14 +11,14 @@ class ChainMigrationElection(Election):
|
||||
ALLOWED_OPERATIONS = (OPERATION,)
|
||||
TX_SCHEMA_CUSTOM = TX_SCHEMA_CHAIN_MIGRATION_ELECTION
|
||||
|
||||
def has_concluded(self, bigchaindb, *args, **kwargs):
|
||||
chain = bigchaindb.get_latest_abci_chain()
|
||||
def has_concluded(self, corechaindb, *args, **kwargs):
|
||||
chain = corechaindb.get_latest_abci_chain()
|
||||
if chain is not None and not chain['is_synced']:
|
||||
# do not conclude the migration election if
|
||||
# there is another migration in progress
|
||||
return False
|
||||
|
||||
return super().has_concluded(bigchaindb, *args, **kwargs)
|
||||
return super().has_concluded(corechaindb, *args, **kwargs)
|
||||
|
||||
def on_approval(self, bigchain, *args, **kwargs):
|
||||
bigchain.migrate_abci_chain()
|
@ -3,12 +3,12 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from bigchaindb.backend.schema import validate_language_key
|
||||
from bigchaindb.common.exceptions import (InvalidSignature,
|
||||
from corechaindb.backend.schema import validate_language_key
|
||||
from corechaindb.common.exceptions import (InvalidSignature,
|
||||
DuplicateTransaction)
|
||||
from bigchaindb.common.schema import validate_transaction_schema
|
||||
from bigchaindb.common.transaction import Transaction
|
||||
from bigchaindb.common.utils import (validate_txn_obj, validate_key)
|
||||
from corechaindb.common.schema import validate_transaction_schema
|
||||
from corechaindb.common.transaction import Transaction
|
||||
from corechaindb.common.utils import (validate_txn_obj, validate_key)
|
||||
|
||||
|
||||
class Transaction(Transaction):
|
||||
@ -19,7 +19,7 @@ class Transaction(Transaction):
|
||||
def validate(self, bigchain, current_transactions=[]):
|
||||
"""Validate transaction spend
|
||||
Args:
|
||||
bigchain (BigchainDB): an instantiated bigchaindb.BigchainDB object.
|
||||
bigchain (BigchainDB): an instantiated corechaindb.BigchainDB object.
|
||||
Returns:
|
||||
The transaction (Transaction) if the transaction is valid else it
|
||||
raises an exception describing the reason why the transaction is
|
@ -6,14 +6,14 @@
|
||||
import multiprocessing as mp
|
||||
from collections import defaultdict
|
||||
|
||||
from bigchaindb import App, BigchainDB
|
||||
from bigchaindb.tendermint_utils import decode_transaction
|
||||
from corechaindb import App, BigchainDB
|
||||
from corechaindb.tendermint_utils import decode_transaction
|
||||
from abci import CodeTypeOk
|
||||
|
||||
|
||||
class ParallelValidationApp(App):
|
||||
def __init__(self, bigchaindb=None, events_queue=None, abci=None):
|
||||
super().__init__(bigchaindb, events_queue, abci=abci)
|
||||
def __init__(self, corechaindb=None, events_queue=None, abci=None):
|
||||
super().__init__(corechaindb, events_queue, abci=abci)
|
||||
self.parallel_validator = ParallelValidator()
|
||||
self.parallel_validator.start()
|
||||
|
||||
@ -88,7 +88,7 @@ class ValidationWorker:
|
||||
def __init__(self, in_queue, results_queue):
|
||||
self.in_queue = in_queue
|
||||
self.results_queue = results_queue
|
||||
self.bigchaindb = BigchainDB()
|
||||
self.corechaindb = BigchainDB()
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
@ -104,7 +104,7 @@ class ValidationWorker:
|
||||
except KeyError:
|
||||
asset_id = dict_transaction['id']
|
||||
|
||||
transaction = self.bigchaindb.is_valid_transaction(
|
||||
transaction = self.corechaindb.is_valid_transaction(
|
||||
dict_transaction,
|
||||
self.validated_transactions[asset_id])
|
||||
|
@ -8,13 +8,13 @@ import setproctitle
|
||||
|
||||
from abci import TmVersion, ABCI
|
||||
|
||||
import bigchaindb
|
||||
from bigchaindb.lib import BigchainDB
|
||||
from bigchaindb.core import App
|
||||
from bigchaindb.parallel_validation import ParallelValidationApp
|
||||
from bigchaindb.web import server, websocket_server
|
||||
from bigchaindb.events import Exchange, EventTypes
|
||||
from bigchaindb.utils import Process
|
||||
import corechaindb
|
||||
from corechaindb.lib import BigchainDB
|
||||
from corechaindb.core import App
|
||||
from corechaindb.parallel_validation import ParallelValidationApp
|
||||
from corechaindb.web import server, websocket_server
|
||||
from corechaindb.events import Exchange, EventTypes
|
||||
from corechaindb.utils import Process
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -28,7 +28,7 @@ BANNER = """
|
||||
* *
|
||||
* You can send HTTP requests via the HTTP API documented in the *
|
||||
* BigchainDB Server docs at: *
|
||||
* https://bigchaindb.com/http-api *
|
||||
* https://corechaindb.com/http-api *
|
||||
* *
|
||||
* Listening to client connections on: {:<15} *
|
||||
* *
|
||||
@ -42,22 +42,22 @@ def start(args):
|
||||
exchange = Exchange()
|
||||
# start the web api
|
||||
app_server = server.create_server(
|
||||
settings=bigchaindb.config['server'],
|
||||
log_config=bigchaindb.config['log'],
|
||||
bigchaindb_factory=BigchainDB)
|
||||
p_webapi = Process(name='bigchaindb_webapi', target=app_server.run, daemon=True)
|
||||
settings=corechaindb.config['server'],
|
||||
log_config=corechaindb.config['log'],
|
||||
corechaindb_factory=BigchainDB)
|
||||
p_webapi = Process(name='corechaindb_webapi', target=app_server.run, daemon=True)
|
||||
p_webapi.start()
|
||||
|
||||
logger.info(BANNER.format(bigchaindb.config['server']['bind']))
|
||||
logger.info(BANNER.format(corechaindb.config['server']['bind']))
|
||||
|
||||
# start websocket server
|
||||
p_websocket_server = Process(name='bigchaindb_ws',
|
||||
p_websocket_server = Process(name='corechaindb_ws',
|
||||
target=websocket_server.start,
|
||||
daemon=True,
|
||||
args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),))
|
||||
p_websocket_server.start()
|
||||
|
||||
p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True)
|
||||
p_exchange = Process(name='corechaindb_exchange', target=exchange.run, daemon=True)
|
||||
p_exchange.start()
|
||||
|
||||
# We need to import this after spawning the web server
|
||||
@ -65,10 +65,10 @@ def start(args):
|
||||
# for gevent.
|
||||
from abci.server import ABCIServer
|
||||
|
||||
setproctitle.setproctitle('bigchaindb')
|
||||
setproctitle.setproctitle('corechaindb')
|
||||
|
||||
# Start the ABCIServer
|
||||
abci = ABCI(TmVersion(bigchaindb.config['tendermint']['version']))
|
||||
abci = ABCI(TmVersion(corechaindb.config['tendermint']['version']))
|
||||
if args.experimental_parallel_validation:
|
||||
app = ABCIServer(
|
||||
app=ParallelValidationApp(
|
@ -4,4 +4,4 @@
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
|
||||
from bigchaindb.upsert_validator.validator_election import ValidatorElection # noqa
|
||||
from corechaindb.upsert_validator.validator_election import ValidatorElection # noqa
|
@ -3,9 +3,9 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from bigchaindb.common.exceptions import InvalidPowerChange
|
||||
from bigchaindb.elections.election import Election
|
||||
from bigchaindb.common.schema import TX_SCHEMA_VALIDATOR_ELECTION
|
||||
from corechaindb.common.exceptions import InvalidPowerChange
|
||||
from corechaindb.elections.election import Election
|
||||
from corechaindb.common.schema import TX_SCHEMA_VALIDATOR_ELECTION
|
||||
from .validator_utils import (new_validator_set, encode_validator, validate_asset_public_key)
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ class ValidatorElection(Election):
|
||||
TX_SCHEMA_CUSTOM = TX_SCHEMA_VALIDATOR_ELECTION
|
||||
|
||||
def validate(self, bigchain, current_transactions=[]):
|
||||
"""For more details refer BEP-21: https://github.com/bigchaindb/BEPs/tree/master/21
|
||||
"""For more details refer BEP-21: https://github.com/corechaindb/BEPs/tree/master/21
|
||||
"""
|
||||
|
||||
current_validators = self.get_validators(bigchain)
|
||||
@ -63,6 +63,6 @@ class ValidatorElection(Election):
|
||||
bigchain.store_validator_set(new_height + 1, updated_validator_set)
|
||||
return encode_validator(self.asset['data'])
|
||||
|
||||
def on_rollback(self, bigchaindb, new_height):
|
||||
def on_rollback(self, corechaindb, new_height):
|
||||
# TODO change to `new_height + 2` when upgrading to Tendermint 0.24.0.
|
||||
bigchaindb.delete_validator_set(new_height + 1)
|
||||
corechaindb.delete_validator_set(new_height + 1)
|
@ -2,16 +2,16 @@ import base64
|
||||
import binascii
|
||||
import codecs
|
||||
|
||||
import bigchaindb
|
||||
import corechaindb
|
||||
from abci import types_v0_22_8, types_v0_31_5, TmVersion
|
||||
from bigchaindb.common.exceptions import InvalidPublicKey, BigchainDBError
|
||||
from corechaindb.common.exceptions import InvalidPublicKey, BigchainDBError
|
||||
|
||||
|
||||
def encode_validator(v):
|
||||
ed25519_public_key = v['public_key']['value']
|
||||
# NOTE: tendermint expects public to be encoded in go-amino format
|
||||
try:
|
||||
version = TmVersion(bigchaindb.config["tendermint"]["version"])
|
||||
version = TmVersion(corechaindb.config["tendermint"]["version"])
|
||||
except ValueError:
|
||||
raise BigchainDBError('Invalid tendermint version, '
|
||||
'check BigchainDB configuration file')
|
@ -11,9 +11,9 @@ import json
|
||||
|
||||
import setproctitle
|
||||
from packaging import version
|
||||
from bigchaindb.version import __tm_supported_versions__
|
||||
from bigchaindb.tendermint_utils import key_from_base64
|
||||
from bigchaindb.common.crypto import key_pair_from_ed25519_key
|
||||
from corechaindb.version import __tm_supported_versions__
|
||||
from corechaindb.tendermint_utils import key_from_base64
|
||||
from corechaindb.common.crypto import key_pair_from_ed25519_key
|
||||
|
||||
|
||||
class ProcessGroup(object):
|
@ -13,13 +13,13 @@ class BaseValidationRules():
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def validate_transaction(bigchaindb, transaction):
|
||||
"""See :meth:`bigchaindb.models.Transaction.validate`
|
||||
def validate_transaction(corechaindb, transaction):
|
||||
"""See :meth:`corechaindb.models.Transaction.validate`
|
||||
for documentation.
|
||||
"""
|
||||
return transaction.validate(bigchaindb)
|
||||
return transaction.validate(corechaindb)
|
||||
|
||||
@staticmethod
|
||||
def validate_block(bigchaindb, block):
|
||||
"""See :meth:`bigchaindb.models.Block.validate` for documentation."""
|
||||
return block.validate(bigchaindb)
|
||||
def validate_block(corechaindb, block):
|
||||
"""See :meth:`corechaindb.models.Block.validate` for documentation."""
|
||||
return block.validate(corechaindb)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user