Skip to content

Commit

Permalink
Diem migration (#172)
Browse files Browse the repository at this point in the history
* Diem migration (#2)

* LIP and url fixes

LIP and url fixes

Co-authored-by: ericnakagawa <[email protected]>
  • Loading branch information
yanivmo and ericnakagawa authored Dec 2, 2020
1 parent d24df76 commit 7059a9e
Show file tree
Hide file tree
Showing 51 changed files with 311 additions and 312 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
/build
/dist
__pycache__
/src/libra_client_sdk.egg-info
/src/diem_client_sdk.egg-info

# JetBrains IDEs configuration
.idea
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "libra"]
path = libra
url = [email protected]:libra/libra.git
12 changes: 6 additions & 6 deletions .pyre_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"taint_models_path": "./venv/lib/pyre_check/taint",
"typeshed": "./venv/lib/pyre_check/typeshed",
"ignore_all_errors": [
"src/libra/jsonrpc/jsonrpc_pb2.py",
"src/libra/lcs",
"src/libra/libra_types",
"src/libra/serde_binary",
"src/libra/serde_types",
"src/libra/stdlib",
"src/diem/jsonrpc/jsonrpc_pb2.py",
"src/diem/lcs",
"src/diem/diem_types",
"src/diem/serde_binary",
"src/diem/serde_types",
"src/diem/stdlib",
"venv"
]
}
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Code of Conduct

The project has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://developers.libra.org/docs/policies/code-of-conduct) so that you can understand what actions will and will not be tolerated.
The project has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://developers.diem.com/docs/policies/code-of-conduct) so that you can understand what actions will and will not be tolerated.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This project welcomes contributions.

## Contributor License Agreement (CLA)

For pull request to be accepted by any Libra projects, a CLA must be [signed](https://libra.org/en-US/cla-sign). You will only need to do this once to work on any of Libra's open source projects.
For pull request to be accepted by any Diem projects, a CLA must be [signed](https://www.diem.com/en-us/cla-sign/). You will only need to do this once to work on any of Diem's open source projects.

When submitting a pull request (PR), the `libra-github-bot` will check your submission for a valid CLA. If one is not found, then you will need to [submit](https://libra.org/en-US/cla-sign) an Individual CLA for yourself or a Corporate CLA for your company.
When submitting a pull request (PR), the `libra-github-bot` will check your submission for a valid CLA. If one is not found, then you will need to [submit](https://www.diem.com/en-us/cla-sign/) an Individual CLA for yourself or a Corporate CLA for your company.

## Issues

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

recursive-include src *.py
30 changes: 15 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

init:
Expand Down Expand Up @@ -30,25 +30,25 @@ cover: install

build: lint test

libratypes:
(cd libra && cargo build -p transaction-builder-generator)
"libra/target/debug/generate-transaction-builders" \
diemtypes:
(cd diem && cargo build -p transaction-builder-generator)
"diem/target/debug/generate-transaction-builders" \
--language python3 \
--module-name stdlib \
--with-libra-types "libra/testsuite/generate-format/tests/staged/libra.yaml" \
--serde-package-name libra \
--libra-package-name libra \
--target-source-dir src/libra \
--with-custom-libra-code libra-types-ext/*.py \
-- "libra/language/stdlib/compiled/transaction_scripts/abi"
--with-libra-types "diem/testsuite/generate-format/tests/staged/libra.yaml" \
--serde-package-name diem \
--libra-package-name diem \
--target-source-dir src/diem \
--with-custom-libra-code diem-types-ext/*.py \
-- "diem/language/stdlib/compiled/transaction_scripts/abi"

protobuf:
mkdir -p src/libra/jsonrpc
mkdir -p src/diem/jsonrpc
protoc --plugin=protoc-gen-mypy=venv/bin/protoc-gen-mypy \
-Ilibra/json-rpc/types/src/proto --python_out=src/libra/jsonrpc --mypy_out=src/libra/jsonrpc \
-Idiem/json-rpc/types/src/proto --python_out=src/diem/jsonrpc --mypy_out=src/diem/jsonrpc \
jsonrpc.proto

gen: libratypes protobuf format
gen: diemtypes protobuf format


dist:
Expand All @@ -65,7 +65,7 @@ tagrelease:

docs: init install
rm -rf docs
./venv/bin/python3 -m pdoc libra --html -o docs
./venv/bin/python3 -m pdoc diem --html -o docs


.PHONY: init check lint format install test cover build libratypes protobuf gen dist pylama docs
.PHONY: init check lint format install test cover build diemtypes protobuf gen dist pylama docs
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
> **Note to readers:** On December 1, 2020, the Libra Association was renamed to Diem Association. The project repos are in the process of being migrated. All projects will remain available for use here until the migration to a new GitHub Organization is complete.
# The official Libra Client SDK for Python.
# The official Diem Client SDK for Python.

[Documentation](https://developers.libra.org/docs/python-client-sdk-docs/libra/)
[Documentation](https://developers.diem.com/docs/python-client-sdk-docs)

## Modules Overview

> SPEC = specification
> LIP-X = Libra Improvement Protocol
> DIP-X = Diem Improvement Protocol
Root module name: `libra`
Root module name: `diem`

Sub-modules:

- `jsonrpc`: libra JSON-RPC APIs client and API response types. [SPEC](https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md)
- `jsonrpc`: diem JSON-RPC APIs client and API response types. [SPEC](https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md)
- `stdlib`: generated code, move stdlib script utils for constructing transaction script playload.
- `libra_types`: generated code, Libra on-chain data structure types for encoding and decoding [LCS](https://libra.github.io/libra/libra_canonical_serialization/index.html) data.
- `diem_types`: generated code, Diem on-chain data structure types for encoding and decoding [LCS](https://libra.github.io/libra/lcs/index.html) data.
- `utils`: utility functions, account address utils, currency code, hashing, hex encoding / decoding, transaction utils.
- `AuthKey` | `auth_key`: auth key utils
- `identifier`: Libra Account Identifier and Libra Intent Identifier. [LIP-5](https://lip.libra.org/lip-5/)
- `txnmetadata`: utils for creating peer to peer transaction metadata. [LIP-4](https://lip.libra.org/lip-4/)
- `identifier`: Diem Account Identifier and Diem Intent Identifier. [DIP-5](https://dip.diem.com/dip-5/)
- `txnmetadata`: utils for creating peer to peer transaction metadata. [DIP-4](https://dip.libra.org/dip-4/)
- `testnet`: Testnet utility, minting coins, create Testnet client, chain id, Testnet JSON-RPC URL.
- `LocalAccount` | `local_account`: utility for managing local account keys, generate random local account.
- `chain_ids`: list of static chain ids
Expand All @@ -29,7 +29,7 @@ Sub-modules:

```python3

>>> from libra import jsonrpc, testnet
>>> from diem import jsonrpc, testnet
>>> client = jsonrpc.Client(testnet.JSON_RPC_URL)
>>> client.get_metadata()
version: 3300304
Expand All @@ -50,7 +50,7 @@ Note: `make test` runs all examples too, see the Makefile for details.
## Download

```
pip install libra-client-sdk
pip install diem-client-sdk
```

## Bugs/Requests
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Security Policies and Procedures

Please see Libra's
[security policies](https://developers.libra.org/docs/policies/security) and
Please see Diem's
[security policies](https://developers.diem.com/docs/reference/security/) and
procedures for reporting vulnerabilities.
32 changes: 16 additions & 16 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
This file is a checklist of requirement & technical details for a Libra client SDK implementation.
This file is a checklist of requirement & technical details for a Diem client SDK implementation.

# Basics

- [x] module structure:
- libra
- LibraClient: JSON-RPC APIs interface, should support application to do easy mock / stub development.
- jsonrpc: jsonrpc client interface, include plain data classes / structs defined in Libra JSON-RPC SPEC document.
- diem
- Client: JSON-RPC APIs interface, should support application to do easy mock / stub development.
- jsonrpc: jsonrpc client interface, include plain data classes / structs defined in Diem JSON-RPC SPEC document.
- types: data transfer object types for jsonrpc client, should match server side JSON-RPC spec data types.
- stdlib: move stdlib script utils.
- testnet: testnet utils, should include FaucetService for handling testnet mint.
- libra-types: Libra onchain data structure types.
- diem_types: Diem onchain data structure types.
- utils:
- signing
- sha3 hashing, address parsing and converting, hex encoding / decoding
- [LIP-4] transaction metadata
- [LIP-5] intent identifier, account identifier
- [DIP-4] transaction metadata
- [DIP-5] intent identifier, account identifier
- [ ] JSON-RPC 2.0 Spec:
- spec version validation.
- batch requests and responses handling.
- [x] JSON-RPC client error handling should distinguish the following 3 type errors:
- Transport layer error, e.g. HTTP call failure.
- JSON-RPC protocol error: e.g. server responds to non json data, or can't be parsed into [Libra JSON-RPC SPEC][1] defined data structure, or missing result & error field.
- JSON-RPC protocol error: e.g. server responds to non json data, or can't be parsed into [Diem JSON-RPC SPEC][1] defined data structure, or missing result & error field.
- JSON-RPC error: error returned from server.
- [x] https.
- [ ] Client connection pool.
Expand All @@ -29,7 +29,7 @@ This file is a checklist of requirement & technical details for a Libra client S
- [x] last known blockchain version >= response version: when connecting to a cluster of fullnodes, it is possible some fullnodes are behind the head couple versions.
- [x] last known blockchain timestamp >= response timestamp.
- [x] parse and use libra_chain_id, libra_ledger_version and libra_ledger_tiemstamp in the JSONRPC response.
- [x] Parsing and gen Libra Account Identifier (see [LIP-5][2])
- [x] Parsing and gen Diem Account Identifier (see [DIP-5][2])
- bech32 addresses/subaddresses support
- [x] language specific standard release publish: e.g. java maven central repo, python pip
- [x] Multi-network: initialize Client with chain id, JSON-RPC server URL
Expand All @@ -39,14 +39,14 @@ This file is a checklist of requirement & technical details for a Libra client S
- [ ] Send request with "client sdk name / version" as HTTP User-Agent: this is for server to recognize client sdk version, so that server can block a specific client version if we found unacceptable bugs.
- [x] Decode transaction script bytes

# [LIP-4][7] support
# [DIP-4][7] support

- [x] Non-custodial to custodial transaction
- [x] Custodial to non-custodial transaction
- [x] Custodial to Custodial transaction
- [x] Refund

# [LIP-5][2] support
# [DIP-5][2] support

- [x] Encode and decode account identifier
- [x] Encode and decode intent identifier
Expand Down Expand Up @@ -88,7 +88,7 @@ See [doc][5] for above concepts.

# Examples

- [x] [p2p transfer examples](https://github.com/libra/lip/blob/master/lips/lip-4.md#transaction-examples)
- [x] [p2p transfer examples](https://github.com/libra/dip/blob/master/dips/dip-4.md#transaction-examples)
- [x] refund p2p transfer example
- [x] create childVASP example
- [x] Intent identifier encoding, decoding example
Expand All @@ -98,10 +98,10 @@ See [doc][5] for above concepts.
- [ ] Async client
- [ ] CLI connects to testnet for trying out features.

[1]: https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md "Libra JSON-RPC SPEC"
[2]: https://github.com/libra/lip/blob/master/lips/lip-5.md "LIP-5"
[1]: https://github.com/libra/libra/blob/master/json-rpc/json-rpc-spec.md "Diem JSON-RPC SPEC"
[2]: https://github.com/libra/dip/blob/master/dips/dip-5.md "DIP-5"
[3]: https://github.com/libra/libra/blob/master/language/stdlib/transaction_scripts/doc/peer_to_peer_with_metadata.md "P2P Transafer"
[4]: https://github.com/libra/libra/tree/master/language/stdlib/transaction_scripts/doc "Move Stdlib scripts"
[5]: https://github.com/libra/libra/blob/master/client/libra-dev/README.md "Libra Client Dev Doc"
[5]: https://github.com/libra/libra/blob/master/client/libra-dev/README.md "Diem Client Dev Doc"
[6]: https://github.com/libra/libra/blob/master/json-rpc/docs/service_testnet_faucet.md "Faucet service"
[7]: https://github.com/libra/lip/blob/master/lips/lip-4.md "Transaction Metadata Specification"
[7]: https://github.com/libra/dip/blob/master/dips/dip-4.md "Transaction Metadata Specification"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions examples/create_child_vasp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0


import time

from libra import (
libra_types,
from diem import (
diem_types,
stdlib,
testnet,
utils,
Expand All @@ -22,10 +22,10 @@ def test_create_child_vasp():

child_vasp = LocalAccount.generate()
currency = testnet.TEST_CURRENCY_CODE
raw_txn = libra_types.RawTransaction(
raw_txn = diem_types.RawTransaction(
sender=parent_vasp.account_address,
sequence_number=seq_num,
payload=libra_types.TransactionPayload__Script(
payload=diem_types.TransactionPayload__Script(
stdlib.encode_create_child_vasp_account_script(
coin_type=utils.currency_code(currency),
child_address=child_vasp.account_address,
Expand Down
6 changes: 3 additions & 3 deletions examples/intent_identifier.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0


import secrets

from libra import identifier, utils, LocalAccount
from diem import identifier, utils, LocalAccount


def test_intent_identifier():
Expand All @@ -18,4 +18,4 @@ def test_intent_identifier():
)
intent_id = identifier.encode_intent(account_id, currency_code, amount)

assert intent_id == "libra://tlb1p6uu2pwv9zvzalcw3wurlppqahjg895qjqd9gsrc5pe4ul?c=Coin1&am=10000000"
assert intent_id == "diem://tlb1p6uu2pwv9zvzalcw3wurlppqahjg895qjqd9gsrc5pe4ul?c=Coin1&am=10000000"
10 changes: 5 additions & 5 deletions examples/p2p_transfer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

import time, secrets, typing

from libra import (
from diem import (
identifier,
jsonrpc,
libra_types,
diem_types,
stdlib,
testnet,
txnmetadata,
Expand Down Expand Up @@ -165,10 +165,10 @@ def test_custodial_to_custodial_above_threshold():


def create_transaction(sender, sender_account_sequence, script, currency):
return libra_types.RawTransaction(
return diem_types.RawTransaction(
sender=sender.account_address,
sequence_number=sender_account_sequence,
payload=libra_types.TransactionPayload__Script(script),
payload=diem_types.TransactionPayload__Script(script),
max_gas_amount=1_000_000,
gas_unit_price=0,
gas_currency_code=currency,
Expand Down
4 changes: 2 additions & 2 deletions examples/refund.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

from libra import (
from diem import (
identifier,
stdlib,
testnet,
Expand Down
14 changes: 7 additions & 7 deletions examples/stubs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

import time, secrets, typing
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from libra import (
from diem import (
identifier,
jsonrpc,
libra_types,
diem_types,
stdlib,
testnet,
utils,
Expand Down Expand Up @@ -91,17 +91,17 @@ def available_child_vasp(self) -> LocalAccount:

def submit_and_wait(
self,
txn: typing.Union[libra_types.SignedTransaction, str],
txn: typing.Union[diem_types.SignedTransaction, str],
) -> jsonrpc.Transaction:
self._client.submit(txn)
return self._client.wait_for_transaction(txn)

def create_transaction(self, sender, script, currency) -> libra_types.RawTransaction:
def create_transaction(self, sender, script, currency) -> diem_types.RawTransaction:
sender_account_sequence = self.get_sequence_number(sender)
return libra_types.RawTransaction(
return diem_types.RawTransaction(
sender=sender.account_address,
sequence_number=sender_account_sequence,
payload=libra_types.TransactionPayload__Script(script),
payload=diem_types.TransactionPayload__Script(script),
max_gas_amount=1_000_000,
gas_unit_price=0,
gas_currency_code=currency,
Expand Down
1 change: 0 additions & 1 deletion libra
Submodule libra deleted from dd3b38
2 changes: 1 addition & 1 deletion pylama.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

[pylama]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) The Libra Core Contributors
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0
[tool.black]
line-length = 120
Expand Down
Loading

0 comments on commit 7059a9e

Please sign in to comment.