@wishknish/knishio-client-js 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +207 -274
- package/dist/client.iife.js +533 -0
- package/package.json +37 -79
- package/src/.babelrc +0 -22
- package/src/Atom.js +171 -132
- package/src/AtomMeta.js +76 -50
- package/src/AuthToken.js +38 -47
- package/src/KnishIOClient.js +934 -987
- package/src/Meta.js +15 -17
- package/src/Molecule.js +423 -494
- package/src/PolicyMeta.js +32 -41
- package/src/TokenUnit.js +30 -32
- package/src/Wallet.js +275 -265
- package/src/exception/AtomIndexException.js +4 -8
- package/src/exception/AtomsMissingException.js +4 -6
- package/src/exception/AuthorizationRejectedException.js +4 -5
- package/src/exception/BalanceInsufficientException.js +4 -8
- package/src/exception/BaseException.js +6 -8
- package/src/exception/BatchIdException.js +5 -7
- package/src/exception/CodeException.js +4 -8
- package/src/{libraries/ApolloLink/HttpLink.js → exception/DecryptionKeyException.js} +12 -15
- package/src/exception/InvalidResponseException.js +4 -5
- package/src/exception/MetaMissingException.js +4 -6
- package/src/exception/MolecularHashMismatchException.js +4 -6
- package/src/exception/MolecularHashMissingException.js +4 -5
- package/src/exception/NegativeAmountException.js +4 -5
- package/src/exception/PolicyInvalidException.js +4 -4
- package/src/exception/SignatureMalformedException.js +4 -5
- package/src/exception/SignatureMismatchException.js +4 -5
- package/src/exception/StackableUnitAmountException.js +4 -5
- package/src/exception/StackableUnitDecimalsException.js +4 -5
- package/src/exception/TransferBalanceException.js +4 -5
- package/src/exception/TransferMalformedException.js +4 -5
- package/src/exception/TransferMismatchedException.js +4 -5
- package/src/exception/TransferRemainderException.js +4 -5
- package/src/exception/TransferToSelfException.js +4 -5
- package/src/exception/TransferUnbalancedException.js +4 -5
- package/src/exception/UnauthenticatedException.js +4 -5
- package/src/{libraries/ApolloLink/AuthLink.js → exception/WalletCredentialException.js} +12 -40
- package/src/exception/WalletShadowException.js +4 -5
- package/src/exception/WrongTokenTypeException.js +4 -5
- package/src/exception/index.js +26 -26
- package/src/index.js +8 -10
- package/src/instance/Rules/Callback.js +91 -93
- package/src/instance/Rules/Condition.js +21 -23
- package/src/instance/Rules/Meta.js +13 -14
- package/src/instance/Rules/Rule.js +39 -43
- package/src/instance/Rules/exception/RuleArgumentException.js +4 -4
- package/src/libraries/CheckMolecule.js +253 -232
- package/src/libraries/Decimal.js +13 -17
- package/src/libraries/Dot.js +74 -48
- package/src/libraries/Hex.js +49 -54
- package/src/libraries/array.js +50 -41
- package/src/libraries/crypto.js +20 -27
- package/src/libraries/strings.js +58 -91
- package/src/libraries/urql/UrqlClientWrapper.js +166 -0
- package/src/mutation/Mutation.js +44 -25
- package/src/mutation/MutationActiveSession.js +12 -12
- package/src/mutation/MutationClaimShadowWallet.js +15 -17
- package/src/mutation/MutationCreateIdentifier.js +11 -12
- package/src/mutation/MutationCreateMeta.js +11 -12
- package/src/mutation/MutationCreateRule.js +11 -12
- package/src/mutation/MutationCreateToken.js +18 -13
- package/src/mutation/MutationCreateWallet.js +9 -11
- package/src/mutation/MutationDepositBufferToken.js +7 -9
- package/src/mutation/MutationLinkIdentifier.js +12 -14
- package/src/mutation/MutationProposeMolecule.js +24 -25
- package/src/mutation/MutationRequestAuthorization.js +9 -10
- package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
- package/src/mutation/MutationRequestTokens.js +11 -14
- package/src/mutation/MutationTransferTokens.js +11 -14
- package/src/mutation/MutationWithdrawBufferToken.js +7 -10
- package/src/query/Query.js +62 -36
- package/src/query/QueryActiveSession.js +11 -13
- package/src/query/QueryAtom.js +75 -76
- package/src/query/QueryBalance.js +11 -12
- package/src/query/QueryBatch.js +17 -14
- package/src/query/QueryBatchHistory.js +16 -13
- package/src/query/QueryContinuId.js +13 -10
- package/src/query/QueryMetaType.js +45 -57
- package/src/query/QueryMetaTypeViaAtom.js +49 -57
- package/src/query/QueryPolicy.js +11 -12
- package/src/query/QueryToken.js +11 -13
- package/src/query/QueryUserActivity.js +11 -13
- package/src/query/QueryWalletBundle.js +15 -47
- package/src/query/QueryWalletList.js +15 -16
- package/src/response/Response.js +29 -34
- package/src/response/ResponseActiveSession.js +6 -6
- package/src/response/ResponseAtom.js +29 -30
- package/src/response/ResponseAuthorizationGuest.js +17 -18
- package/src/response/ResponseBalance.js +12 -13
- package/src/response/ResponseClaimShadowWallet.js +1 -1
- package/src/response/ResponseContinuId.js +21 -22
- package/src/response/ResponseCreateIdentifier.js +1 -1
- package/src/response/ResponseCreateMeta.js +1 -1
- package/src/response/ResponseCreateRule.js +1 -1
- package/src/response/ResponseCreateToken.js +1 -1
- package/src/response/ResponseCreateWallet.js +1 -1
- package/src/response/ResponseLinkIdentifier.js +9 -10
- package/src/response/ResponseMetaBatch.js +6 -8
- package/src/response/ResponseMetaType.js +19 -20
- package/src/response/ResponseMetaTypeViaAtom.js +19 -19
- package/src/response/ResponsePolicy.js +14 -15
- package/src/response/ResponseProposeMolecule.js +27 -30
- package/src/response/ResponseQueryActiveSession.js +20 -23
- package/src/response/ResponseQueryUserActivity.js +11 -12
- package/src/response/ResponseRequestAuthorization.js +11 -16
- package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
- package/src/response/ResponseRequestTokens.js +1 -1
- package/src/response/ResponseTransferTokens.js +8 -9
- package/src/response/ResponseWalletBundle.js +16 -17
- package/src/response/ResponseWalletList.js +44 -47
- package/src/subscribe/ActiveSessionSubscribe.js +5 -6
- package/src/subscribe/ActiveWalletSubscribe.js +5 -6
- package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
- package/src/subscribe/Subscribe.js +26 -26
- package/src/subscribe/WalletStatusSubscribe.js +5 -6
- package/src/versions/HashAtom.js +78 -0
- package/src/versions/Version4.js +34 -0
- package/src/versions/index.js +5 -0
- package/dist/client.umd.js +0 -453
- package/src/httpClient/ApolloClient.js +0 -245
- package/src/libraries/ApolloLink/CipherLink.js +0 -117
- package/src/libraries/ApolloLink/Client.js +0 -231
- package/src/libraries/ApolloLink/PusherLink.js +0 -234
- package/src/libraries/ApolloLink/handler.js +0 -106
- package/src/libraries/Base58.js +0 -71
- package/src/libraries/Base64.js +0 -40
- package/src/libraries/BaseX.js +0 -91
- package/src/libraries/Soda.js +0 -93
- package/src/query/QueryMetaInstance.js +0 -99
- package/src/test/Test.js +0 -670
- package/src/test/TestTokenUnit.js +0 -340
|
@@ -45,13 +45,12 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import BaseException from './BaseException'
|
|
48
|
+
import BaseException from './BaseException'
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Thrown when V isotope atom amounts do not add up to zero
|
|
52
52
|
*/
|
|
53
53
|
export default class TransferUnbalancedException extends BaseException {
|
|
54
|
-
|
|
55
54
|
/**
|
|
56
55
|
* Class constructor
|
|
57
56
|
*
|
|
@@ -59,8 +58,8 @@ export default class TransferUnbalancedException extends BaseException {
|
|
|
59
58
|
* @param {string|null} fileName
|
|
60
59
|
* @param {number|null} lineNumber
|
|
61
60
|
*/
|
|
62
|
-
constructor (
|
|
63
|
-
super(
|
|
64
|
-
this.name = 'TransferUnbalancedException'
|
|
61
|
+
constructor (message = 'Token transfer atoms are unbalanced', fileName = null, lineNumber = null) {
|
|
62
|
+
super(message, fileName, lineNumber)
|
|
63
|
+
this.name = 'TransferUnbalancedException'
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -45,13 +45,12 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import BaseException from './BaseException'
|
|
48
|
+
import BaseException from './BaseException'
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Thrown when attempting to transact without an auth token
|
|
52
52
|
*/
|
|
53
53
|
export default class UnauthenticatedException extends BaseException {
|
|
54
|
-
|
|
55
54
|
/**
|
|
56
55
|
* Class constructor
|
|
57
56
|
*
|
|
@@ -59,8 +58,8 @@ export default class UnauthenticatedException extends BaseException {
|
|
|
59
58
|
* @param {string|null} fileName
|
|
60
59
|
* @param {number|null} lineNumber
|
|
61
60
|
*/
|
|
62
|
-
constructor (
|
|
63
|
-
super(
|
|
64
|
-
this.name = 'UnauthenticatedException'
|
|
61
|
+
constructor (message = 'Authorization token missing or invalid.', fileName = null, lineNumber = null) {
|
|
62
|
+
super(message, fileName, lineNumber)
|
|
63
|
+
this.name = 'UnauthenticatedException'
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -45,49 +45,21 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class AuthLink extends ApolloLink {
|
|
52
|
-
|
|
53
|
-
constructor () {
|
|
54
|
-
super();
|
|
55
|
-
|
|
56
|
-
this.auth = '';
|
|
57
|
-
}
|
|
48
|
+
import BaseException from './BaseException'
|
|
58
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when failing to retrieve shadow wallets
|
|
52
|
+
*/
|
|
53
|
+
export default class WalletCredentialException extends BaseException {
|
|
59
54
|
/**
|
|
55
|
+
* Class constructor
|
|
60
56
|
*
|
|
61
|
-
* @
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return this.auth;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @param {string} auth
|
|
57
|
+
* @param {string} message
|
|
58
|
+
* @param {string|null} fileName
|
|
59
|
+
* @param {number|null} lineNumber
|
|
69
60
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @param {Operation} operation
|
|
77
|
-
* @param {NextLink | undefined} forward
|
|
78
|
-
* @returns {Observable<FetchResult> | null}
|
|
79
|
-
*/
|
|
80
|
-
request ( operation, forward ) {
|
|
81
|
-
|
|
82
|
-
operation.setContext( ( { headers = {} } ) => ( {
|
|
83
|
-
headers: {
|
|
84
|
-
...headers,
|
|
85
|
-
'X-Auth-Token': this.getAuthToken()
|
|
86
|
-
}
|
|
87
|
-
} ) );
|
|
88
|
-
|
|
89
|
-
return forward( operation );
|
|
61
|
+
constructor (message = 'Attempting to create a wallet with no credentials (secret or bundle hash)', fileName = null, lineNumber = null) {
|
|
62
|
+
super(message, fileName, lineNumber)
|
|
63
|
+
this.name = 'WalletCredentialException'
|
|
90
64
|
}
|
|
91
65
|
}
|
|
92
|
-
|
|
93
|
-
export default AuthLink;
|
|
@@ -45,13 +45,12 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import BaseException from './BaseException'
|
|
48
|
+
import BaseException from './BaseException'
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Thrown when failing to retrieve shadow wallets
|
|
52
52
|
*/
|
|
53
53
|
export default class WalletShadowException extends BaseException {
|
|
54
|
-
|
|
55
54
|
/**
|
|
56
55
|
* Class constructor
|
|
57
56
|
*
|
|
@@ -59,8 +58,8 @@ export default class WalletShadowException extends BaseException {
|
|
|
59
58
|
* @param {string|null} fileName
|
|
60
59
|
* @param {number|null} lineNumber
|
|
61
60
|
*/
|
|
62
|
-
constructor (
|
|
63
|
-
super(
|
|
64
|
-
this.name = 'WalletShadowException'
|
|
61
|
+
constructor (message = 'The shadow wallet does not exist', fileName = null, lineNumber = null) {
|
|
62
|
+
super(message, fileName, lineNumber)
|
|
63
|
+
this.name = 'WalletShadowException'
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -45,13 +45,12 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import BaseException from './BaseException'
|
|
48
|
+
import BaseException from './BaseException'
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Thrown when trying to use an inappropriate token slug for a particular isotope
|
|
52
52
|
*/
|
|
53
53
|
export default class WrongTokenTypeException extends BaseException {
|
|
54
|
-
|
|
55
54
|
/**
|
|
56
55
|
* Class constructor
|
|
57
56
|
*
|
|
@@ -59,8 +58,8 @@ export default class WrongTokenTypeException extends BaseException {
|
|
|
59
58
|
* @param {string|null} fileName
|
|
60
59
|
* @param {number|null} lineNumber
|
|
61
60
|
*/
|
|
62
|
-
constructor (
|
|
63
|
-
super(
|
|
64
|
-
this.name = 'WrongTokenTypeException'
|
|
61
|
+
constructor (message = 'Wrong type of token for this isotope', fileName = null, lineNumber = null) {
|
|
62
|
+
super(message, fileName, lineNumber)
|
|
63
|
+
this.name = 'WrongTokenTypeException'
|
|
65
64
|
}
|
|
66
65
|
}
|
package/src/exception/index.js
CHANGED
|
@@ -45,31 +45,31 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
45
45
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
|
-
import AtomIndexException from './AtomIndexException'
|
|
49
|
-
import AtomsMissingException from './AtomsMissingException'
|
|
50
|
-
import AuthorizationRejectedException from './AuthorizationRejectedException'
|
|
51
|
-
import BalanceInsufficientException from './BalanceInsufficientException'
|
|
52
|
-
import BatchIdException from './BatchIdException'
|
|
53
|
-
import CodeException from './CodeException'
|
|
54
|
-
import InvalidResponseException from './InvalidResponseException'
|
|
55
|
-
import MetaMissingException from './MetaMissingException'
|
|
56
|
-
import MolecularHashMismatchException from './MolecularHashMismatchException'
|
|
57
|
-
import MolecularHashMissingException from './MolecularHashMissingException'
|
|
58
|
-
import NegativeAmountException from './NegativeAmountException'
|
|
59
|
-
import PolicyInvalidException from './PolicyInvalidException'
|
|
60
|
-
import SignatureMalformedException from './SignatureMalformedException'
|
|
61
|
-
import SignatureMismatchException from './SignatureMismatchException'
|
|
62
|
-
import StackableUnitAmountException from './StackableUnitAmountException'
|
|
63
|
-
import StackableUnitDecimalsException from './StackableUnitDecimalsException'
|
|
64
|
-
import TransferBalanceException from './TransferBalanceException'
|
|
65
|
-
import TransferMalformedException from './TransferMalformedException'
|
|
66
|
-
import TransferMismatchedException from './TransferMismatchedException'
|
|
67
|
-
import TransferRemainderException from './TransferRemainderException'
|
|
68
|
-
import TransferToSelfException from './TransferToSelfException'
|
|
69
|
-
import TransferUnbalancedException from './TransferUnbalancedException'
|
|
70
|
-
import UnauthenticatedException from './UnauthenticatedException'
|
|
71
|
-
import WalletShadowException from './WalletShadowException'
|
|
72
|
-
import WrongTokenTypeException from './WrongTokenTypeException'
|
|
48
|
+
import AtomIndexException from './AtomIndexException'
|
|
49
|
+
import AtomsMissingException from './AtomsMissingException'
|
|
50
|
+
import AuthorizationRejectedException from './AuthorizationRejectedException'
|
|
51
|
+
import BalanceInsufficientException from './BalanceInsufficientException'
|
|
52
|
+
import BatchIdException from './BatchIdException'
|
|
53
|
+
import CodeException from './CodeException'
|
|
54
|
+
import InvalidResponseException from './InvalidResponseException'
|
|
55
|
+
import MetaMissingException from './MetaMissingException'
|
|
56
|
+
import MolecularHashMismatchException from './MolecularHashMismatchException'
|
|
57
|
+
import MolecularHashMissingException from './MolecularHashMissingException'
|
|
58
|
+
import NegativeAmountException from './NegativeAmountException'
|
|
59
|
+
import PolicyInvalidException from './PolicyInvalidException'
|
|
60
|
+
import SignatureMalformedException from './SignatureMalformedException'
|
|
61
|
+
import SignatureMismatchException from './SignatureMismatchException'
|
|
62
|
+
import StackableUnitAmountException from './StackableUnitAmountException'
|
|
63
|
+
import StackableUnitDecimalsException from './StackableUnitDecimalsException'
|
|
64
|
+
import TransferBalanceException from './TransferBalanceException'
|
|
65
|
+
import TransferMalformedException from './TransferMalformedException'
|
|
66
|
+
import TransferMismatchedException from './TransferMismatchedException'
|
|
67
|
+
import TransferRemainderException from './TransferRemainderException'
|
|
68
|
+
import TransferToSelfException from './TransferToSelfException'
|
|
69
|
+
import TransferUnbalancedException from './TransferUnbalancedException'
|
|
70
|
+
import UnauthenticatedException from './UnauthenticatedException'
|
|
71
|
+
import WalletShadowException from './WalletShadowException'
|
|
72
|
+
import WrongTokenTypeException from './WrongTokenTypeException'
|
|
73
73
|
|
|
74
74
|
export {
|
|
75
75
|
AtomIndexException,
|
|
@@ -97,4 +97,4 @@ export {
|
|
|
97
97
|
UnauthenticatedException,
|
|
98
98
|
WalletShadowException,
|
|
99
99
|
WrongTokenTypeException
|
|
100
|
-
}
|
|
100
|
+
}
|
package/src/index.js
CHANGED
|
@@ -46,12 +46,11 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
-
import Atom from './Atom'
|
|
50
|
-
import Molecule from './Molecule'
|
|
51
|
-
import Wallet from './Wallet'
|
|
52
|
-
import Meta from './Meta'
|
|
53
|
-
import KnishIOClient from './KnishIOClient'
|
|
54
|
-
import Test from './test/Test';
|
|
49
|
+
import Atom from './Atom'
|
|
50
|
+
import Molecule from './Molecule'
|
|
51
|
+
import Wallet from './Wallet'
|
|
52
|
+
import Meta from './Meta'
|
|
53
|
+
import KnishIOClient from './KnishIOClient'
|
|
55
54
|
import {
|
|
56
55
|
base64ToHex,
|
|
57
56
|
bufferToHexString,
|
|
@@ -61,11 +60,11 @@ import {
|
|
|
61
60
|
hexToBase64,
|
|
62
61
|
isHex,
|
|
63
62
|
randomString
|
|
64
|
-
} from './libraries/strings'
|
|
63
|
+
} from './libraries/strings'
|
|
65
64
|
import {
|
|
66
65
|
generateBundleHash,
|
|
67
66
|
generateSecret
|
|
68
|
-
} from './libraries/crypto'
|
|
67
|
+
} from './libraries/crypto'
|
|
69
68
|
|
|
70
69
|
export {
|
|
71
70
|
Atom,
|
|
@@ -73,7 +72,6 @@ export {
|
|
|
73
72
|
Wallet,
|
|
74
73
|
Meta,
|
|
75
74
|
KnishIOClient,
|
|
76
|
-
Test,
|
|
77
75
|
|
|
78
76
|
// strings
|
|
79
77
|
chunkSubstr,
|
|
@@ -88,4 +86,4 @@ export {
|
|
|
88
86
|
// crypto
|
|
89
87
|
generateSecret,
|
|
90
88
|
generateBundleHash
|
|
91
|
-
}
|
|
89
|
+
}
|
|
@@ -46,14 +46,13 @@ Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
|
|
|
46
46
|
License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
-
import Meta from './Meta'
|
|
50
|
-
import RuleArgumentException from './exception/RuleArgumentException'
|
|
51
|
-
import { isNumeric } from '../../libraries/strings'
|
|
52
|
-
import { intersect } from '../../libraries/array'
|
|
53
|
-
import CodeException from '../../exception/CodeException'
|
|
49
|
+
import Meta from './Meta'
|
|
50
|
+
import RuleArgumentException from './exception/RuleArgumentException'
|
|
51
|
+
import { isNumeric } from '../../libraries/strings'
|
|
52
|
+
import { intersect } from '../../libraries/array'
|
|
53
|
+
import CodeException from '../../exception/CodeException'
|
|
54
54
|
|
|
55
55
|
export default class Callback {
|
|
56
|
-
|
|
57
56
|
/**
|
|
58
57
|
*
|
|
59
58
|
* @param {string} action
|
|
@@ -65,7 +64,7 @@ export default class Callback {
|
|
|
65
64
|
* @param {string|null} amount
|
|
66
65
|
* @param {string|null} comparison
|
|
67
66
|
*/
|
|
68
|
-
constructor (
|
|
67
|
+
constructor ({
|
|
69
68
|
action,
|
|
70
69
|
metaType = null,
|
|
71
70
|
metaId = null,
|
|
@@ -74,214 +73,213 @@ export default class Callback {
|
|
|
74
73
|
token = null,
|
|
75
74
|
amount = null,
|
|
76
75
|
comparison = null
|
|
77
|
-
}
|
|
78
|
-
if (
|
|
79
|
-
this.meta = meta
|
|
76
|
+
}) {
|
|
77
|
+
if (meta) {
|
|
78
|
+
this.meta = meta
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
if (
|
|
83
|
-
throw new RuleArgumentException(
|
|
81
|
+
if (!action) {
|
|
82
|
+
throw new RuleArgumentException('Callback structure violated, missing mandatory "action" parameter.')
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
this.__metaId = metaId
|
|
87
|
-
this.__metaType = metaType
|
|
88
|
-
this.__action = action
|
|
89
|
-
this.__address = address
|
|
90
|
-
this.__token = token
|
|
91
|
-
this.__amount = amount
|
|
92
|
-
this.__comparison = comparison
|
|
85
|
+
this.__metaId = metaId
|
|
86
|
+
this.__metaType = metaType
|
|
87
|
+
this.__action = action
|
|
88
|
+
this.__address = address
|
|
89
|
+
this.__token = token
|
|
90
|
+
this.__amount = amount
|
|
91
|
+
this.__comparison = comparison
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
/**
|
|
96
95
|
*
|
|
97
96
|
* @param {string} comparison
|
|
98
97
|
*/
|
|
99
|
-
set comparison (
|
|
100
|
-
this.__comparison = comparison
|
|
98
|
+
set comparison (comparison) {
|
|
99
|
+
this.__comparison = comparison
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
/**
|
|
104
103
|
*
|
|
105
104
|
* @param {string} amount
|
|
106
105
|
*/
|
|
107
|
-
set amount (
|
|
108
|
-
if (
|
|
109
|
-
throw new CodeException('Parameter amount should be a string containing numbers')
|
|
106
|
+
set amount (amount) {
|
|
107
|
+
if (!isNumeric(amount)) {
|
|
108
|
+
throw new CodeException('Parameter amount should be a string containing numbers')
|
|
110
109
|
}
|
|
111
|
-
this.__amount = amount
|
|
110
|
+
this.__amount = amount
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
/**
|
|
115
114
|
*
|
|
116
115
|
* @param {string} token
|
|
117
116
|
*/
|
|
118
|
-
set token (
|
|
119
|
-
this.__token = token
|
|
117
|
+
set token (token) {
|
|
118
|
+
this.__token = token
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
/**
|
|
123
122
|
*
|
|
124
123
|
* @param {string} address
|
|
125
124
|
*/
|
|
126
|
-
set address (
|
|
127
|
-
this.__address = address
|
|
125
|
+
set address (address) {
|
|
126
|
+
this.__address = address
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
/**
|
|
131
130
|
*
|
|
132
131
|
* @param {Meta|object} meta
|
|
133
132
|
*/
|
|
134
|
-
set meta (
|
|
135
|
-
this.__meta = meta instanceof Meta ? meta : Meta.toObject(
|
|
133
|
+
set meta (meta) {
|
|
134
|
+
this.__meta = meta instanceof Meta ? meta : Meta.toObject(meta)
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
/**
|
|
139
138
|
*
|
|
140
139
|
* @param {string} metaType
|
|
141
140
|
*/
|
|
142
|
-
set metaType (
|
|
143
|
-
this.__metaType = metaType
|
|
141
|
+
set metaType (metaType) {
|
|
142
|
+
this.__metaType = metaType
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
/**
|
|
147
146
|
*
|
|
148
147
|
* @param {string} metaId
|
|
149
148
|
*/
|
|
150
|
-
set metaId (
|
|
151
|
-
this.__metaId = metaId
|
|
149
|
+
set metaId (metaId) {
|
|
150
|
+
this.__metaId = metaId
|
|
152
151
|
}
|
|
153
152
|
|
|
154
|
-
|
|
155
153
|
/**
|
|
156
154
|
*
|
|
157
|
-
* @
|
|
155
|
+
* @param {object} object
|
|
156
|
+
*
|
|
157
|
+
* @return Callback
|
|
158
158
|
*/
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
action:
|
|
162
|
-
}
|
|
159
|
+
static toObject (object) {
|
|
160
|
+
const callback = new Callback({
|
|
161
|
+
action: object.action
|
|
162
|
+
})
|
|
163
163
|
|
|
164
|
-
if (
|
|
165
|
-
|
|
164
|
+
if (object.metaType) {
|
|
165
|
+
callback.metaType = object.metaType
|
|
166
166
|
}
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
|
|
168
|
+
if (object.metaId) {
|
|
169
|
+
callback.metaId = object.metaId
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
|
|
172
|
+
if (object.meta) {
|
|
173
|
+
callback.meta = object.meta
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
+
if (object.address) {
|
|
177
|
+
callback.address = object.address
|
|
176
178
|
}
|
|
177
179
|
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
+
if (object.token) {
|
|
181
|
+
callback.token = object.token
|
|
180
182
|
}
|
|
181
183
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
+
if (object.amount) {
|
|
185
|
+
callback.amount = object.amount
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
+
if (object.comparison) {
|
|
189
|
+
callback.comparison = object.comparison
|
|
188
190
|
}
|
|
189
191
|
|
|
190
|
-
return
|
|
192
|
+
return callback
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
/**
|
|
194
196
|
*
|
|
195
|
-
* @
|
|
196
|
-
*
|
|
197
|
-
* @return Callback
|
|
197
|
+
* @return {{action: string}}
|
|
198
198
|
*/
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
action:
|
|
202
|
-
} );
|
|
203
|
-
|
|
204
|
-
if ( object.metaType ) {
|
|
205
|
-
callback.metaType = object.metaType;
|
|
199
|
+
toJSON () {
|
|
200
|
+
const meta = {
|
|
201
|
+
action: this.__action
|
|
206
202
|
}
|
|
207
203
|
|
|
208
|
-
if (
|
|
209
|
-
|
|
204
|
+
if (this.__metaType) {
|
|
205
|
+
meta.metaType = this.__metaType
|
|
210
206
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
207
|
+
if (this.__metaId) {
|
|
208
|
+
meta.metaId = this.__metaId
|
|
209
|
+
}
|
|
210
|
+
if (this.__meta) {
|
|
211
|
+
meta.meta = this.__meta
|
|
214
212
|
}
|
|
215
213
|
|
|
216
|
-
if (
|
|
217
|
-
|
|
214
|
+
if (this.__address) {
|
|
215
|
+
meta.address = this.__address
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
if (
|
|
221
|
-
|
|
218
|
+
if (this.__token) {
|
|
219
|
+
meta.token = this.__token
|
|
222
220
|
}
|
|
223
221
|
|
|
224
|
-
if (
|
|
225
|
-
|
|
222
|
+
if (this.__amount) {
|
|
223
|
+
meta.amount = this.__amount
|
|
226
224
|
}
|
|
227
225
|
|
|
228
|
-
if (
|
|
229
|
-
|
|
226
|
+
if (this.__comparison) {
|
|
227
|
+
meta.comparison = this.__comparison
|
|
230
228
|
}
|
|
231
229
|
|
|
232
|
-
return
|
|
230
|
+
return meta
|
|
233
231
|
}
|
|
234
232
|
|
|
235
233
|
/**
|
|
236
234
|
* @return {boolean}
|
|
237
235
|
*/
|
|
238
236
|
isReject () {
|
|
239
|
-
return this._is(
|
|
237
|
+
return this._is('reject')
|
|
240
238
|
}
|
|
241
239
|
|
|
242
240
|
/**
|
|
243
241
|
* @return {boolean}
|
|
244
242
|
*/
|
|
245
243
|
isMeta () {
|
|
246
|
-
const prop = intersect(
|
|
244
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'metaId', 'metaType', 'meta'])
|
|
247
245
|
|
|
248
|
-
return prop.length === 4 && this._is(
|
|
246
|
+
return prop.length === 4 && this._is('meta')
|
|
249
247
|
}
|
|
250
248
|
|
|
251
249
|
/**
|
|
252
250
|
* @return {boolean}
|
|
253
251
|
*/
|
|
254
252
|
isCollect () {
|
|
255
|
-
const prop = intersect(
|
|
253
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'address', 'token', 'amount', 'comparison'])
|
|
256
254
|
|
|
257
|
-
return prop.length === 5 && this._is(
|
|
255
|
+
return prop.length === 5 && this._is('collect')
|
|
258
256
|
}
|
|
259
257
|
|
|
260
258
|
/**
|
|
261
259
|
* @return {boolean}
|
|
262
260
|
*/
|
|
263
261
|
isBuffer () {
|
|
264
|
-
const prop = intersect(
|
|
262
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'address', 'token', 'amount', 'comparison'])
|
|
265
263
|
|
|
266
|
-
return prop.length === 5 && this._is(
|
|
264
|
+
return prop.length === 5 && this._is('buffer')
|
|
267
265
|
}
|
|
268
266
|
|
|
269
267
|
/**
|
|
270
268
|
* @return {boolean}
|
|
271
269
|
*/
|
|
272
270
|
isRemit () {
|
|
273
|
-
const prop = intersect(
|
|
271
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'token', 'amount'])
|
|
274
272
|
|
|
275
|
-
return prop.length === 3 && this._is(
|
|
273
|
+
return prop.length === 3 && this._is('remit')
|
|
276
274
|
}
|
|
277
275
|
|
|
278
276
|
/**
|
|
279
277
|
* @return {boolean}
|
|
280
278
|
*/
|
|
281
279
|
isBurn () {
|
|
282
|
-
const prop = intersect(
|
|
280
|
+
const prop = intersect(Object.keys(this.toJSON()), ['action', 'token', 'amount', 'comparison'])
|
|
283
281
|
|
|
284
|
-
return prop.length === 4 && this._is(
|
|
282
|
+
return prop.length === 4 && this._is('burn')
|
|
285
283
|
}
|
|
286
284
|
|
|
287
285
|
/**
|
|
@@ -290,7 +288,7 @@ export default class Callback {
|
|
|
290
288
|
* @return {boolean}
|
|
291
289
|
* @private
|
|
292
290
|
*/
|
|
293
|
-
_is(
|
|
294
|
-
return this.__action.toLowerCase() === type.toLowerCase()
|
|
291
|
+
_is (type) {
|
|
292
|
+
return this.__action.toLowerCase() === type.toLowerCase()
|
|
295
293
|
}
|
|
296
294
|
}
|