Skip to content

Commit

Permalink
refactor(AE): Remove all deprecated stuff (#697)
Browse files Browse the repository at this point in the history
* refactor(AE): Remove all deprecated stuff

* chore(merge): Remove unused import

* chore(merge): Minor fixes

* refactor(Test): Fix merge conflict

* refactor(Test): Remove deprecated keyPair structure(priv/pub)

* refactor(Compiler): Move commander to devDependencies

* refactor(Compiler): Node-pool covarage
  • Loading branch information
nduchak committed Dec 17, 2019
1 parent b29a162 commit ef895ee
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 144 deletions.
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -116,18 +116,11 @@ Promise.all([
Node({ url, internalUrl })
]).then(nodes => {
Ae({
// This two params deprecated and will be remove in next major release
url: 'https://sdk-testnet.aepps.com',
internalUrl: 'https://sdk-testnet.aepps.com',
// instead use
nodes: [
{ name: 'someNode', instance: nodes[0] },
// node2, node3..
],
compilerUrl: 'COMPILER_URL',
// `keypair` param deprecated and will be removed in next major release
keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' },
// instead use
accounts: [
MemoryAccount({ keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' } }),
// acc2
Expand Down
7 changes: 4 additions & 3 deletions docs/examples/node/aewallet.md
Expand Up @@ -60,10 +60,10 @@ We'll need the main client module `Ae` in the `Universal` flavor from the SDK.


```js
const { Universal: Ae } = require('@aeternity/aepp-sdk')
const { Universal: Ae, Node } = require('@aeternity/aepp-sdk')
const program = require('commander')

function spend (receiver, amount, { host, debug }) {
async function spend (receiver, amount, { host, debug }) {

```
Expand All @@ -82,7 +82,8 @@ the implementation grab the key pair from the `WALLET_PRIV` and
```js
Ae({ url: host, debug, process })
const node = await Node({ url: host })
Ae({ nodes: [{ name: 'local', instance: node }], debug, process })
.then(ae => ae.spend(parseInt(amount), receiver))
.then(tx => console.log('Transaction mined', tx))
.catch(e => console.log(e.message))
Expand Down
17 changes: 2 additions & 15 deletions docs/guides/import-nodejs.md
Expand Up @@ -15,17 +15,11 @@ Promise.all([
node1
]).then(nodes => {
Ae({
// This two params deprecated and will be remove in next major release
url: 'https://sdk-testnet.aepps.com',
internalUrl: 'https://sdk-testnet.aepps.com',
// instead use
nodes: [
{ name: 'someNode', instance: nodes[0] },
// mode2
// node2
],
compilerUrl: 'COMPILER_URL',
// `keypair` param deprecated and will be removed in next major release
keypair: 'YOUR_KEYPAIR_OBJECT',
// instead use
accounts: [
acc1,
Expand All @@ -48,18 +42,11 @@ const main = async () => {
// const acc2 = ...

const client = await Ae({
// This two params deprecated and will be remove in next major release
url: 'https://sdk-testnet.aepps.com',
internalUrl: 'https://sdk-testnet.aepps.com',
// instead use
nodes: [
{ name: 'someNode', instance: node1 },
// mode2
// node2
],
compilerUrl: 'COMPILER_URL',
// `keypair` param deprecated and will be removed in next major release
keypair: 'YOUR_KEYPAIR_OBJECT',
// instead use
accounts: [
acc1,
// acc2
Expand Down
14 changes: 8 additions & 6 deletions docs/guides/import-script-tag.md
Expand Up @@ -27,12 +27,14 @@ The bundle will assign the SDK to a global `var` called `Ae`, and you can use it
<!-- include latest SDK version -->
<script src="https://unpkg.com/@aeternity/aepp-sdk/dist/aepp-sdk.browser-script.js"></script>
<script type="text/javascript">
Ae.Wallet({
url: 'https://sdk-testnet.aepps.com'
}).then(aeInstance => {
aeInstance.height().then(height => {
console.log("Current Block Height:" + height)
})
Ae.Node({ url: 'https://sdk-testnet.aepps.com' }).then(node => {
Ae.Wallet({
nodes: [{ name: 'local', instance: node }]
}).then(aeInstance => {
aeInstance.height().then(height => {
console.log("Current Block Height:" + height)
})
})
})
</script>
</body>
Expand Down
4 changes: 0 additions & 4 deletions docs/guides/low-vs-high-usage.md
Expand Up @@ -27,10 +27,6 @@ Example spend function, using aeternity's SDK abstraction
// const node1 = await Node({ url, internalUrl })

Wallet({
// This two params deprecated and will be remove in next major release
url: 'https://sdk-testnet.aepps.com',
internalUrl: 'https://sdk-testnet.aepps.com',
// instead use
nodes: [
// { name: 'someNode', instance: node1 },
// mode2
Expand Down
7 changes: 0 additions & 7 deletions es/account/memory.js
Expand Up @@ -47,9 +47,6 @@ function setSecret (keyPair) {

function validateKeyPair (keyPair) {
if (!keyPair || typeof keyPair !== 'object') throw new Error('KeyPair must be an object')
if (keyPair.pub && keyPair.priv) {
keyPair = { publicKey: keyPair.pub, secretKey: keyPair.priv }
}
if (!keyPair.secretKey || !keyPair.publicKey) throw new Error('KeyPair must must have "secretKey", "publicKey" properties')
if (typeof keyPair.publicKey !== 'string' || keyPair.publicKey.indexOf('ak_') === -1) throw new Error('Public Key must be a base58c string with "ak_" prefix')
if (
Expand Down Expand Up @@ -80,10 +77,6 @@ const MemoryAccount = Account.compose({
secrets.set(this, { publicKey: gaId })
} else {
validateKeyPair(keypair)
if (Object.prototype.hasOwnProperty.call(keypair, 'priv') && Object.prototype.hasOwnProperty.call(keypair, 'pub')) {
keypair = { secretKey: keypair.priv, publicKey: keypair.pub }
console.warn('pub/priv naming for accounts has been deprecated, please use secretKey/publicKey')
}

this.setSecret(keypair)
}
Expand Down
36 changes: 4 additions & 32 deletions es/accounts.js
Expand Up @@ -27,31 +27,7 @@ import AsyncInit from './utils/async-init'
import * as R from 'ramda'
import MemoryAccount from './account/memory'
import Selector from './account/selector'
import { envKeypair, generateKeyPair } from './utils/crypto'

/**
* Select specific account
* @deprecated
* @alias module:@aeternity/aepp-sdk/es/accounts
* @function
* @rtype (keypair: {publicKey: String, secretKey: String}) => Void
* @param {Object} keypair - Key pair to use
* @param {String} keypair.publicKey - Public key
* @param {String} keypair.secretKey - Private key
* @return {Void}
* @example setKeypair(keypair)
*/
function setKeypair (keypair) {
const acc = this.accounts[this.Selector.address] || this._acc
if (Object.prototype.hasOwnProperty.call(keypair, 'priv') && Object.prototype.hasOwnProperty.call(keypair, 'pub')) {
keypair = { secretKey: keypair.priv, publicKey: keypair.pub }
console.warn('pub/priv naming for accounts has been deprecated, please use secretKey/publicKey')
}
acc.setSecret(keypair)
this.accounts[keypair.publicKey] = acc
delete this.accounts[this.Selector.address]
this.selectAccount(keypair.publicKey)
}
import { envKeypair } from './utils/crypto'

/**
* Sign data blob with specific key
Expand Down Expand Up @@ -138,21 +114,17 @@ function addresses () {
* accounts.addresses() // Get available accounts
*/
const Accounts = stampit(AsyncInit, {
async init ({ accounts = [], keypair }) { // Deprecated. TODO Remove `keypair` param
async init ({ accounts = [] }) {
this.accounts = R.fromPairs(await Promise.all(accounts.map(async a => [await a.address(), a])))
keypair = keypair || envKeypair(process.env, true)
const keypair = envKeypair(process.env, true)
if (keypair) {
await this.addAccount(MemoryAccount({ keypair }), { select: !this.Selector.address })
}
// @Todo Remove after removing depricated `setKeypair` fn.
// Prevent BREAKING CHANGES
// Pre-init memoryAccount object to prevent async operation in `setKeypair` function
this._acc = MemoryAccount({ keypair: generateKeyPair() })
},
props: {
accounts: {}
},
methods: { signWith, addAccount, removeAccount, setKeypair, addresses }
methods: { signWith, addAccount, removeAccount, addresses }
}, Selector)

export default Accounts
11 changes: 6 additions & 5 deletions es/ae/contract.js
Expand Up @@ -35,6 +35,7 @@ import ContractBase from '../contract'
import ContractACI from '../contract/aci'
import BigNumber from 'bignumber.js'
import NodePool from '../node-pool'
import { AMOUNT, DEPOSIT, DRY_RUN_ACCOUNT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'

function sendAndProcess (tx, options) {
return async function (onSuccess, onError) {
Expand Down Expand Up @@ -349,12 +350,12 @@ export const ContractAPI = Ae.compose(ContractBase, ContractACI, {
deepProps: {
Ae: {
defaults: {
deposit: 0,
gasPrice: 1000000000, // min gasPrice 1e9
amount: 0,
gas: 1600000 - 21000,
deposit: DEPOSIT,
gasPrice: MIN_GAS_PRICE, // min gasPrice 1e9
amount: AMOUNT,
gas: GAS,
options: '',
dryRunAccount: { pub: 'ak_11111111111111111111111111111111273Yts', amount: '100000000000000000000000000000000000' }
dryRunAccount: DRY_RUN_ACCOUNT
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions es/ae/oracle.js
Expand Up @@ -29,6 +29,7 @@
import Ae from './'
import * as R from 'ramda'
import { decodeBase64Check } from '../utils/crypto'
import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'

/**
* Constructor for Oracle Object (helper object for using Oracle)
Expand Down Expand Up @@ -281,10 +282,10 @@ const Oracle = Ae.compose({
deepProps: {
Ae: {
defaults: {
queryFee: 30000,
oracleTtl: { type: 'delta', value: 500 },
queryTtl: { type: 'delta', value: 10 },
responseTtl: { type: 'delta', value: 10 }
queryFee: QUERY_FEE,
oracleTtl: ORACLE_TTL,
queryTtl: QUERY_TTL,
responseTtl: RESPONSE_TTL
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions es/contract/aci/index.js
Expand Up @@ -32,6 +32,7 @@ import AsyncInit from '../../utils/async-init'
import { BigNumber } from 'bignumber.js'
import { COMPILER_LT_VERSION } from '../compiler'
import semverSatisfies from '../../utils/semver-satisfies'
import { AMOUNT, DEPOSIT, GAS, MIN_GAS_PRICE } from '../../tx/builder/schema'

/**
* Validated contract call arguments using contract ACI
Expand Down Expand Up @@ -81,10 +82,10 @@ async function getContractInstance (source, { aci, contractAddress, filesystem =
skipArgsConvert: false,
skipTransformDecoded: false,
callStatic: false,
deposit: 0,
gasPrice: 1000000000, // min gasPrice 1e9
amount: 0,
gas: 1600000 - 21000,
deposit: DEPOSIT,
gasPrice: MIN_GAS_PRICE, // min gasPrice 1e9
amount: AMOUNT,
gas: GAS,
top: null, // using for contract call static
waitMined: true,
verify: false,
Expand Down
1 change: 1 addition & 0 deletions es/contract/ga/helpers.js
Expand Up @@ -18,6 +18,7 @@ export const prepareGaParams = (ins) => async (authData, authFnName) => {

export const getContractAuthFan = (ins) => async (source, fnName) => {
const { bytecode } = await ins.contractCompile(source)

return { bytecode, authFun: hash(fnName) }
}

Expand Down
13 changes: 3 additions & 10 deletions es/node-pool/index.js
Expand Up @@ -4,7 +4,6 @@
* @export NodePool
* @example import NodePool from '@aeternity/aepp-sdk/es/node-pool'
*/
import Node from '../node'
import { DEFAULT_NETWORK_ID, getterForCurrentNode, prepareNodeObject } from './helpers'
import AsyncInit from '../utils/async-init'

Expand All @@ -19,21 +18,15 @@ import AsyncInit from '../utils/async-init'
* @return {Object} NodePool instance
*/
export const NodePool = AsyncInit.compose({
async init ({ nodes = [], url = this.url, internalUrl = this.internalUrl, forceCompatibility = false } = {}) {
async init ({ nodes = [] } = {}) {
this.pool = new Map()
this.validateNodes(nodes)

nodes.forEach(node => {
nodes.forEach((node, i) => {
const { name, instance } = node
this.pool.set(name, prepareNodeObject(name, instance))
this.addNode(name, instance, i === 0)
})
if (nodes.length) this.selectNode(nodes[0].name)

// DEPRECATED. TODO Remove deprecated param
// Prevent BREAKING CHANGES. Support for init params `url`, `internalUrl`
if (url) {
this.addNode('default', await Node({ url, internalUrl, forceCompatibility }), true)
}
},
propertyDescriptors: {
api: {
Expand Down
16 changes: 12 additions & 4 deletions es/tx/builder/schema.js
Expand Up @@ -14,7 +14,18 @@ export const VSN_2 = 2

// # TRANSACTION DEFAULT TTL
export const TX_TTL = 0

// # ORACLE
export const QUERY_FEE = 30000
export const ORACLE_TTL = { type: 'delta', value: 500 }
export const QUERY_TTL = { type: 'delta', value: 10 }
export const RESPONSE_TTL = { type: 'delta', value: 10 }
// # CONTRACT
export const DEPOSIT = 0
export const AMOUNT = 0
export const GAS = 1600000 - 21000
export const MIN_GAS_PRICE = 1000000000 // min gasPrice 1e9
export const MAX_AUTH_FUN_GAS = 50000
export const DRY_RUN_ACCOUNT = { pub: 'ak_11111111111111111111111111111111273Yts', amount: '100000000000000000000000000000000000' }
// # AENS
export const AENS_NAME_DOMAINS = ['chain', 'test']
export const NAME_TTL = 50000
Expand Down Expand Up @@ -137,9 +148,6 @@ const OBJECT_TAG_SOPHIA_BYTE_CODE = 70
const TX_FIELD = (name, type, prefix) => [name, type, prefix]
const TX_SCHEMA_FIELD = (schema, objectId) => [schema, objectId]

export const MIN_GAS_PRICE = 1000000000 // min gasPrice 1e9
export const MAX_AUTH_FUN_GAS = 50000 // min gasPrice 1e9

const revertObject = (obj) => Object.entries(obj).reduce((acc, [key, v]) => (acc[v] = key) && acc, {})

/**
Expand Down
4 changes: 2 additions & 2 deletions es/tx/tx.js
Expand Up @@ -452,8 +452,8 @@ const Transaction = ChainNode.compose(Tx, {
this.showWarning = showWarning
},
props: {
nativeMode: null,
showWarning: null
nativeMode: true,
showWarning: false
},
methods: {
spendTx,
Expand Down
1 change: 0 additions & 1 deletion es/utils/keystore.js
Expand Up @@ -8,7 +8,6 @@ const _sodium = require('libsodium-wrappers-sumo')

/**
* KeyStore module
* !!!Work only in node.js!!!
* @module @aeternity/aepp-sdk/es/utils/keystore
* @example import * as Keystore from '@aeternity/aepp-sdk/es/utils/keystore'
* @example const { Keystore } = require('@aeternity/aepp-sdk')
Expand Down
15 changes: 2 additions & 13 deletions examples/README.md
Expand Up @@ -24,23 +24,16 @@ import Node from '@aeternity/aepp-sdk/es/node'
// const node1 = await Node({ url })

Ae({
// This two params deprecated and will be remove in next major release
url: 'https://sdk-testnet.aepps.com',
internalUrl: 'https://sdk-testnet.aepps.com',
// instead use
nodes: [
// { name: 'someNode', instance: node1 },
// mode2
// node2
],
compilerUrl: 'https://compiler.aepps.com',
// `keypair` param deprecated and will be removed in next major release
keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' },
// instead use
accounts: [
MemoryAccount({ keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' } }),
// acc2
],
address: 'SELECTED_ACCOUNT_PUB'
address: 'SELECTED_ACCOUNT_PUB',
networkId: 'ae_uat' // or any other networkId your client should connect to
}).then(ae => {

Expand Down Expand Up @@ -81,10 +74,6 @@ const confirmDialog = function (method, params, {id}) {
}

Wallet({
// This two params deprecated and will be remove in next major release
url: 'https://sdk-testnet.aepps.com',
internalUrl: 'https://sdk-testnet.aepps.com',
// instead use
nodes: [
// { name: 'someNode', instance: node1 },
// mode2
Expand Down

0 comments on commit ef895ee

Please sign in to comment.