Skip to content

Commit

Permalink
Merge pull request #72 from Concordium/cis2-invoke
Browse files Browse the repository at this point in the history
Cis2 invoke
  • Loading branch information
abizjak authored Nov 9, 2022
2 parents c6ad619 + efc9e4c commit 0c00e2f
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased changes

## 0.21

Add support for CIS2TokenMetadata and CIS2TokenBalance queries.

## 0.20

Add support for protocol version 5.
Expand Down
99 changes: 95 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The wallet proxy provides the following endpoints:
of a transfer or credential deployment
* `PUT /v0/submitCredential`: deploy a credential/create an account
* `PUT /v0/submitTransfer`: perform a simple transfer
* `GET /v0/accTransactions/{accountNumber}`: get the transactions affecting an account
* `GET /v1/accTransactions/{accountNumber}`: get the transactions affecting an account, including memos
* `PUT /v0/testnetGTUDrop/{accountNumber}`: request a CCD drop to the specified account
* `GET /v0/accTransactions/{account address}`: get the transactions affecting an account
* `GET /v1/accTransactions/{account address}`: get the transactions affecting an account, including memos
* `PUT /v0/testnetGTUDrop/{account address}`: request a CCD drop to the specified account
* `GET /v0/health`: get a response specifying if the wallet proxy is up to date
* `GET /v0/global`: get the cryptographic parameters obtained from the node it is connected to
* `GET /v0/ip_info`: get the identity providers information, including links for
Expand All @@ -29,7 +29,10 @@ The wallet proxy provides the following endpoints:
* `GET /v0/appSettings`: get the up-to-date status of the old mobile wallet app.
* `GET /v1/appSettings`: get the up-to-date status of the new mobile wallet app.
* `GET /v0/epochLength`: get the epoch length in milliseconds.
* `GET /v0/CIS2Tokens`: get the list of tokens on a given contract address.
* `GET /v0/CIS2Tokens/{index}/{subindex}`: get the list of tokens on a given contract address.
* `GET /v0/CIS2TokenMetadata/{index}/{subindex}`: get the metadata of tokens in on given contract address.
* `GET /v0/CIS2TokenMetadata/{index}/{subindex}/{account address}`: get the balance of tokens on given contract address for a given account address.


### Errors

Expand Down Expand Up @@ -729,6 +732,94 @@ The return value is an object with fields
- `totalSupply` ... a non-negative integer (encoded in a string) that records the total
supply of the token as computed by using `Mint` and `Burn` events.

## Get metadata URL for a list of tokens

The endpoint `v0/CIS2TokenMetadata/index/subindex` retrieves a list of token
metadata URLs.

The following parameters are supported and required
- `tokenId`: a comma separated list of token IDs. Token IDs are hex encoded, in
the same format as that returned by `CIS2Tokens` endpoint. An empty string is interpreted
as a single token with an empty ID.

The return value is a JSON list of objects with fields
- `metadataURL` (required) ... a string value that contains a URL returned by
the contract. The client should do validation that this is a usable URL, since
it is purely up to the smart contract to return this value.
- `tokenId` (required) ... the token ID as in the query
- `metadataChecksum` (optional) ... if `null` then no checksum is included in
the contract. Otherwise it is a hex string that contains the SHA256 hash of the **data at the URL**.

An example query is
```
v0/CIS2TokenMetadata/996/0?tokenId=0b5000b73a53f0916c93c68f4b9b6ba8af5a10978634ae4f2237e1f3fbe324fa,1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8,1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8
```

and an example response is
```json
[
{
"metadataChecksum": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"metadataURL": "https://some.example/token/0B5000B73A53F0916C93C68F4B9B6BA8AF5A10978634AE4F2237E1F3FBE324FA",
"tokenId": "0b5000b73a53f0916c93c68f4b9b6ba8af5a10978634ae4f2237e1f3fbe324fa"
},
{
"metadataChecksum": null,
"metadataURL": "https://some.example/token/1209FE3BC3497E47376DFBD9DF0600A17C63384C85F859671956D8289E5A0BE8",
"tokenId": "1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8"
},
{
"metadataChecksum": null,
"metadataURL": "https://some.example/token/1209FE3BC3497E47376DFBD9DF0600A17C63384C85F859671956D8289E5A0BE8",
"tokenId": "1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8"
}
]
```

## Get token balance for an account address

The endpoint `v0/CIS2TokenBalance/index/subindex/accountAddress` retrieves the
balance of tokens for the given account address.

The following parameters are supported and required
- `tokenId`: a comma separated list of token IDs. Token IDs are hex encoded, in
the same format as that returned by `CIS2Tokens` endpoint. An empty string is interpreted
as a single token with an empty ID.

The return value is a JSON list of objects with fields

- `balance` (required) ... a string that contains the balance as a decimal
number. The balance is always non-negative, but can be very large, and will
not fit into a 64-bit integer in general. The value should always fit into a
256-bit unsigned integer though. Generally unbounded integral type should be
used for parsing. The metadata contains information on how to display this
amount, i.e., with how many decimals.
- `tokenId` (required) ... the token ID as in the query

An example query is
```
v0/CIS2TokenBalance/996/0/4tSmWDREJwsSzfgNkUeT7xrNdAPHEs8gQBBdiRsmcvnjFeogf6?tokenId=0b5000b73a53f0916c93c68f4b9b6ba8af5a10978634ae4f2237e1f3fbe324fa,1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8,1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8
```

and an example response is
```json
[
{
"balance": "188848148218418242823213123123123",
"tokenId": "0b5000b73a53f0916c93c68f4b9b6ba8af5a10978634ae4f2237e1f3fbe324fa"
},
{
"balance": "0",
"tokenId": "1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8"
},
{
"balance": "1",
"tokenId": "1209fe3bc3497e47376dfbd9df0600a17c63384c85f859671956d8289e5a0be8"
}
]
```


## Notes on account balances.

Suppose that at time t₀ you query the account balance and get a structure
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wallet-proxy
version: 0.20.0
version: 0.21.0
github: "Concordium/concordium-wallet-proxy"
author: "Concordium"
maintainer: "developers@concordium.com"
Expand Down
4 changes: 4 additions & 0 deletions src/Internationalization/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ data ErrorMessage
| EMMissingParameter
-- |Action not supported due to the node protocol version not allowing it.
| EMActionNotCurrentlySupported
-- |Invoke of a smart contract failed with the given reason.
| EMInvokeFailed
-- |Expected a V1 contract, but a V0 contract was given.
| EMV0Contract

data I18n = I18n {
i18nRejectReason :: RejectReason -> Text,
Expand Down
2 changes: 2 additions & 0 deletions src/Internationalization/En.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,5 @@ translation = I18n {..}
i18nErrorMessage EMAccountDoesNotExist = "Account does not exist"
i18nErrorMessage EMMissingParameter = "Missing parameter"
i18nErrorMessage EMActionNotCurrentlySupported = "The required action is not supported. The node's protocol version is incompatible with it."
i18nErrorMessage EMInvokeFailed = "Invoking a contract failed."
i18nErrorMessage EMV0Contract = "Invoking a V0 contract is not supported."
Loading

0 comments on commit 0c00e2f

Please sign in to comment.