Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.4.1 #323

Merged
merged 15 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
All notable changes to this project will be documented in this file. This change
log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## [2.4.1]
### Added
- feat(ACI): Add transform decoded data for 'address' type
- feat(Aepp): Add Compiler to Aepp rpc methods. Update example app
- feat(Channel): Add call contract static support
- feat(Channel): Add get contract state support
- feat(Channel): Get full channel state support
- docs(*): Adjust ACI, Contract nad Usage
### Changed
- refactor(Http): Handle no response in http stamp error handler
- fix(Crypto): Fix crypto `formatAddress`
- fix(Crypto): Move ADDRESS_FORMAT to crypto

### Removed
- none

### Breaking Changes
- State Channel:
- `channel.state()` now returns offchain state instead of last co-signed offchain transaction
- `channel.update(...).state` has been renamed to `signedTx`
- `channel.withdraw(...).state` has been renamed to `signedTx`
- `channel.deposit(...).state` has been renamed to `signedTx`
- `channel.leave().state` has been renamed to `signedTx`
- `channel.createContract(...).state` has been renamed to `signedTx`
- `channel.callContract(...).state` has been renamed to `signedTx`

### Notes and known Issues
- none


## [2.4.0]
### Added
- Install and configure `commitizen`
Expand Down Expand Up @@ -628,4 +658,5 @@ await account.address(format: ADDRESS_FORMAT) // default ADDRESS_FORMAT.api
[2.3.0]: https://github.com/aeternity/aepp-sdk-js/compare/2.3.0-next...2.3.0
[2.3.1]: https://github.com/aeternity/aepp-sdk-js/compare/2.3.0...2.3.1
[2.3.2]: https://github.com/aeternity/aepp-sdk-js/compare/2.3.1...2.3.2
[2.4.0.]: https://github.com/aeternity/aepp-sdk-js/compare/2.3.2...2.4.0
[2.4.0]: https://github.com/aeternity/aepp-sdk-js/compare/2.3.2...2.4.0
[2.4.1]: https://github.com/aeternity/aepp-sdk-js/compare/2.4.0...2.4.1
104 changes: 83 additions & 21 deletions docs/api/ae/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import { Contract } from '@aeternity/aepp-sdk' (Using bundle)
```

* [@aeternity/aepp-sdk/es/ae/contract](#module_@aeternity/aepp-sdk/es/ae/contract)
* [Contract([options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--Contract) ⇒ `Object` ⏏
* [exports.Contract([options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--exports.Contract) ⇒ `Object` ⏏
* _async_
* [handleCallError(result)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--handleCallError) ⇒ `Promise.<void>` ⏏
* [encodeCall(source, name, args)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--encodeCall) ⇒ `Promise.<String>` ⏏
* [decode(type, data)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--decode) ⇒ `Promise.<String>` ⏏
* [callStatic(source, address, name, args, options, top, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--callStatic) ⇒ `Promise.<Object>` ⏏
* [call(source, address, name, args, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--call) ⇒ `Promise.<Object>` ⏏
* [deploy(code, source, initState, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--deploy) ⇒ `Promise.<Object>` ⏏
* [compile(source, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--compile) ⇒ `Promise.<Object>` ⏏
* [contractEncodeCall(source, name, args)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractEncodeCall) ⇒ `Promise.<String>` ⏏
* [contractDecodeData(type, data)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractDecodeData) ⇒ `Promise.<String>` ⏏
* [contractCallStatic(source, address, name, args, options, top, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCallStatic) ⇒ `Promise.<Object>` ⏏
* [contractCall(source, address, name, args, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCall) ⇒ `Promise.<Object>` ⏏
* [contractDeploy(code, source, initState, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractDeploy) ⇒ `Promise.<Object>` ⏏
* [contractCompile(source, options)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCompile) ⇒ `Promise.<Object>` ⏏

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--Contract"></a>
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--exports.Contract"></a>

### Contract([options]) ⇒ `Object` ⏏
### exports.Contract([options]) ⇒ `Object` ⏏
Contract Stamp

Provide contract implementation
Expand All @@ -43,6 +43,25 @@ Provide contract implementation
| --- | --- | --- | --- |
| [options] | `Object` | <code>{}</code> | Initializer object |

**Example**
```js
import Transaction from '@aeternity/aepp-sdk/es/tx/tx
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory
import ChainNode from '@aeternity/aepp-sdk/es/chain/node
import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler
// or using bundle
import {
Transaction,
MemoryAccount,
ChainNode,
ContractCompilerAPI
} from '@aeternity/aepp-sdk

const ContractWithAE = await Contract
.compose(Transaction, MemoryAccount, ChainNode) // AE implementation
.compose(ContractCompilerAPI) // ContractBase implementation
const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... })
```
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--handleCallError"></a>

### handleCallError(result) ⇒ `Promise.&lt;void&gt;` ⏏
Expand All @@ -59,9 +78,9 @@ Handle contract call error
| --- | --- | --- |
| result | `Object` | call result object |

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--encodeCall"></a>
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--contractEncodeCall"></a>

### encodeCall(source, name, args) ⇒ `Promise.&lt;String&gt;` ⏏
### contractEncodeCall(source, name, args) ⇒ `Promise.&lt;String&gt;` ⏏
Encode call data for contract call

**Kind**: Exported function
Expand All @@ -73,9 +92,9 @@ Encode call data for contract call
| name | `String` | Name of function to call |
| args | `Array` | Argument's for call |

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--decode"></a>
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--contractDecodeData"></a>

### decode(type, data) ⇒ `Promise.&lt;String&gt;` ⏏
### contractDecodeData(type, data) ⇒ `Promise.&lt;String&gt;` ⏏
Decode contract call result data

**Kind**: Exported function
Expand All @@ -87,9 +106,13 @@ Decode contract call result data
| type | `String` | Data type (int, string, list,...) |
| data | `String` | call result data (cb_iwer89fjsdf2j93fjews_(ssdffsdfsdf...) |

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--callStatic"></a>
**Example**
```js
const decodedData = await client.contractDecodeData('string' ,'cb_sf;ls43fsdfsdf...')
```
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCallStatic"></a>

### callStatic(source, address, name, args, options, top, options) ⇒ `Promise.&lt;Object&gt;` ⏏
### contractCallStatic(source, address, name, args, options, top, options) ⇒ `Promise.&lt;Object&gt;` ⏏
Static contract call(using dry-run)

**Kind**: Exported function
Expand All @@ -106,9 +129,17 @@ Static contract call(using dry-run)
| top | `String` | [options.top] Block hash on which you want to call contract |
| options | `String` | [options.options] Transaction options (fee, ttl, gas, amount, deposit) |

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--call"></a>
**Example**
```js
const callResult = await client.contractCallStatic(source, address, fnName, args = [], { top, options = {} })
{
result: TX_DATA,
decode: (type) => Decode call result
}
```
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCall"></a>

### call(source, address, name, args, options) ⇒ `Promise.&lt;Object&gt;` ⏏
### contractCall(source, address, name, args, options) ⇒ `Promise.&lt;Object&gt;` ⏏
Call contract function

**Kind**: Exported function
Expand All @@ -123,9 +154,18 @@ Call contract function
| args | `Array` | Argument's for call function |
| options | `Object` | Transaction options (fee, ttl, gas, amount, deposit) |

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--deploy"></a>
**Example**
```js
const callResult = await client.contractCall(source, address, fnName, args = [], options)
{
hash: TX_HASH,
result: TX_DATA,
decode: (type) => Decode call result
}
```
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--contractDeploy"></a>

### deploy(code, source, initState, options) ⇒ `Promise.&lt;Object&gt;` ⏏
### contractDeploy(code, source, initState, options) ⇒ `Promise.&lt;Object&gt;` ⏏
Deploy contract to the node

**Kind**: Exported function
Expand All @@ -139,9 +179,22 @@ Deploy contract to the node
| initState | `Array` | Arguments of contract constructor(init) function |
| options | `Object` | Transaction options (fee, ttl, gas, amount, deposit) |

<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--compile"></a>
**Example**
```js
const deployed = await client.contractDeploy(bytecode, source, init = [], options)
{
owner: OWNER_PUB_KEY,
transaction: TX_HASH,
address: CONTRACT_ADDRESS,
createdAt: Date,
result: DEPLOY_TX_DATA,
call: (fnName, args = [], options) => Call contract function,
callStatic: (fnName, args = [], options) => Static all contract function
}
```
<a id="exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCompile"></a>

### compile(source, options) ⇒ `Promise.&lt;Object&gt;` ⏏
### contractCompile(source, options) ⇒ `Promise.&lt;Object&gt;` ⏏
Compile contract source code

**Kind**: Exported function
Expand All @@ -153,3 +206,12 @@ Compile contract source code
| source | `String` | Contract sourece code |
| options | `Object` | Transaction options (fee, ttl, gas, amount, deposit) |

**Example**
```js
const compiled = await client.contractCompile(SOURCE_CODE)
{
bytecode: CONTRACT_BYTE_CODE,
deploy: (init = [], options = {}) => Deploy Contract,
encodeCall: (fnName, args = []) => Prepare callData
}
```
93 changes: 93 additions & 0 deletions docs/api/channel/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import Channel from '@aeternity/aepp-sdk/es/channel/index'
* [~shutdown(sign)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..shutdown) ⇒ `Promise.&lt;string&gt;`
* [~withdraw(amount, sign, [callbacks])](#module_@aeternity/aepp-sdk/es/channel/index--Channel..withdraw) ⇒ `Promise.&lt;object&gt;`
* [~deposit(amount, sign, [callbacks])](#module_@aeternity/aepp-sdk/es/channel/index--Channel..deposit) ⇒ `Promise.&lt;object&gt;`
* [~createContract(options, sign)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..createContract) ⇒ `Promise.&lt;object&gt;`
* [~callContract(options, sign)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..callContract) ⇒ `Promise.&lt;object&gt;`
* [~getContractCall(options)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..getContractCall) ⇒ `Promise.&lt;object&gt;`
* [~sendMessage(message, recipient)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..sendMessage)

<a id="exp_module_@aeternity/aepp-sdk/es/channel/index--Channel"></a>
Expand Down Expand Up @@ -256,6 +259,96 @@ channel.deposit(
}
})
```
<a id="module_@aeternity/aepp-sdk/es/channel/index--Channel..createContract"></a>

#### Channel~createContract(options, sign) ⇒ `Promise.&lt;object&gt;`
Create a contract

**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)

| Param | Type | Description |
| --- | --- | --- |
| options | `object` | |
| [options.code] | `string` | Api encoded compiled AEVM byte code |
| [options.callData] | `string` | Api encoded compiled AEVM call data for the code |
| [options.deposit] | `number` | Initial amount the owner of the contract commits to it |
| [options.vmVersion] | `number` | Version of the AEVM |
| [options.abiVersion] | `number` | Version of the ABI |
| sign | `function` | Function which verifies and signs create contract transaction |

**Example**
```js
channel.createContract({
code: 'cb_HKtpipK4aCgYb17wZ...',
callData: 'cb_1111111111111111...',
deposit: 10,
vmVersion: 3,
abiVersion: 1
}).then(({ accepted, state, address }) => {
if (accepted) {
console.log('New contract has been created')
console.log('Contract address:', address)
} else {
console.log('New contract has been rejected')
}
})
```
<a id="module_@aeternity/aepp-sdk/es/channel/index--Channel..callContract"></a>

#### Channel~callContract(options, sign) ⇒ `Promise.&lt;object&gt;`
Call a contract

**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)

| Param | Type | Description |
| --- | --- | --- |
| options | `object` | |
| [options.amount] | `string` | Amount the caller of the contract commits to it |
| [options.callData] | `string` | ABI encoded compiled AEVM call data for the code |
| [options.contract] | `number` | Address of the contract to call |
| [options.abiVersion] | `number` | Version of the ABI |
| sign | `function` | Function which verifies and signs contract call transaction |

**Example**
```js
channel.callContract({
contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
callData: 'cb_1111111111111111...',
amount: 0,
abiVersion: 1
}).then(({ accepted, state }) => {
if (accepted) {
console.log('Contract called succesfully')
console.log('The new state is:', state)
} else {
console.log('Contract call has been rejected')
}
})
```
<a id="module_@aeternity/aepp-sdk/es/channel/index--Channel..getContractCall"></a>

#### Channel~getContractCall(options) ⇒ `Promise.&lt;object&gt;`
Get contract call result

**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)

| Param | Type | Description |
| --- | --- | --- |
| options | `object` | |
| [options.caller] | `string` | Address of contract caller |
| [options.contract] | `string` | Address of the contract |
| [options.round] | `number` | Round when contract was called |

**Example**
```js
channel.getContractCall({
caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',
contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',
round: 3
}).then(({ returnType, returnValue }) => {
if (returnType === 'ok') console.log(returnValue)
})
```
<a id="module_@aeternity/aepp-sdk/es/channel/index--Channel..sendMessage"></a>

#### Channel~sendMessage(message, recipient)
Expand Down
8 changes: 8 additions & 0 deletions docs/api/contract/aci.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ Generate contract ACI object with predefined js methods for contract usage
| [options] | `Object` | Options object |
| [options.aci] | `Object` | Contract ACI |

**Example**
```js
const contractIns = await client.getContractInstance(sourceCode)
await contractIns.compile()
await contractIns.deploy([321])
const callResult = await contractIns.call('setState', [123])
const staticCallResult = await contractIns.call('setState', [123], { callStatic: true })
```
<a id="exp_module_@aeternity/aepp-sdk/es/contract/aci--ContractACI"></a>

### ContractACI() ⇒ `Object` ⏏
Expand Down
30 changes: 30 additions & 0 deletions docs/api/utils/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import * as Crypto from '@aeternity/aepp-sdk/es/utils/crypto'
* [.encodeBase58Check(input)](#module_@aeternity/aepp-sdk/es/utils/crypto.encodeBase58Check) ⇒ `Buffer`
* [.decodeBase58Check(str)](#module_@aeternity/aepp-sdk/es/utils/crypto.decodeBase58Check) ⇒ `Buffer`
* [.hexStringToByte(str)](#module_@aeternity/aepp-sdk/es/utils/crypto.hexStringToByte) ⇒ `Uint8Array`
* [.encodeUnsigned(value)](#module_@aeternity/aepp-sdk/es/utils/crypto.encodeUnsigned) ⇒ `Buffer`
* [.encodeContractAddress(owner, nonce)](#module_@aeternity/aepp-sdk/es/utils/crypto.encodeContractAddress) ⇒ `String`
* [.generateKeyPairFromSecret(secret)](#module_@aeternity/aepp-sdk/es/utils/crypto.generateKeyPairFromSecret) ⇒ `Object`
* [.generateKeyPair(raw)](#module_@aeternity/aepp-sdk/es/utils/crypto.generateKeyPair) ⇒ `Object`
* [.encryptPublicKey(password, binaryKey)](#module_@aeternity/aepp-sdk/es/utils/crypto.encryptPublicKey) ⇒ `Uint8Array`
Expand Down Expand Up @@ -238,6 +240,34 @@ Conver hex string to Uint8Array
| --- | --- | --- |
| str | `String` | Data to conver |

<a id="module_@aeternity/aepp-sdk/es/utils/crypto.encodeUnsigned"></a>

### @aeternity/aepp-sdk/es/utils/crypto.encodeUnsigned(value) ⇒ `Buffer`
Converts a positive integer to the smallest possible
representation in a binary digit representation

**Kind**: static method of [`@aeternity/aepp-sdk/es/utils/crypto`](#module_@aeternity/aepp-sdk/es/utils/crypto)
**Returns**: `Buffer` - - Encoded data
**rtype**: `(value: Number) => Buffer`

| Param | Type | Description |
| --- | --- | --- |
| value | `Number` | Value to encode |

<a id="module_@aeternity/aepp-sdk/es/utils/crypto.encodeContractAddress"></a>

### @aeternity/aepp-sdk/es/utils/crypto.encodeContractAddress(owner, nonce) ⇒ `String`
Compute contract address

**Kind**: static method of [`@aeternity/aepp-sdk/es/utils/crypto`](#module_@aeternity/aepp-sdk/es/utils/crypto)
**Returns**: `String` - - Contract address
**rtype**: `(owner: String, nonce: Number) => String`

| Param | Type | Description |
| --- | --- | --- |
| owner | `String` | Address of contract owner |
| nonce | `Number` | Round when contract was created |

<a id="module_@aeternity/aepp-sdk/es/utils/crypto.generateKeyPairFromSecret"></a>

### @aeternity/aepp-sdk/es/utils/crypto.generateKeyPairFromSecret(secret) ⇒ `Object`
Expand Down
Loading