@tech-bureau/mijin-catapult-tools 0.2.0 → 0.2.2
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 +15 -13
- package/dist/main.js +1 -1
- package/dist/src/commands/namespace/namespace.d.ts.map +1 -1
- package/dist/src/commands/namespace/unlinkAddress.d.ts +4 -0
- package/dist/src/commands/namespace/unlinkAddress.d.ts.map +1 -0
- package/dist/src/commands/namespace/unlinkMosaic.d.ts +4 -0
- package/dist/src/commands/namespace/unlinkMosaic.d.ts.map +1 -0
- package/dist/src/infrastructure/namespace/unlinkAddress.d.ts +4 -0
- package/dist/src/infrastructure/namespace/unlinkAddress.d.ts.map +1 -0
- package/dist/src/infrastructure/namespace/unlinkMosaic.d.ts +4 -0
- package/dist/src/infrastructure/namespace/unlinkMosaic.d.ts.map +1 -0
- package/dist/src/service/NamespaceServices.d.ts +2 -0
- package/dist/src/service/NamespaceServices.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/service/NamespaceServices.spec.ts +16 -0
- package/src/commands/namespace/namespace.ts +4 -0
- package/src/commands/namespace/unlinkAddress.ts +17 -0
- package/src/commands/namespace/unlinkMosaic.ts +17 -0
- package/src/infrastructure/namespace/unlinkAddress.ts +126 -0
- package/src/infrastructure/namespace/unlinkMosaic.ts +126 -0
- package/src/service/NamespaceServices.ts +53 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../../src/commands/namespace/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../../src/commands/namespace/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASnC,QAAA,MAAM,MAAM,eAcX,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unlinkAddress.d.ts","sourceRoot":"","sources":["../../../../src/commands/namespace/unlinkAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAc7B,eAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unlinkMosaic.d.ts","sourceRoot":"","sources":["../../../../src/commands/namespace/unlinkMosaic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAc7B,eAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unlinkAddress.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/namespace/unlinkAddress.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;iCAQtB,sBAAsB;AAApD,wBAmHC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unlinkMosaic.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/namespace/unlinkMosaic.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;iCAQtB,sBAAsB;AAApD,wBAmHC"}
|
|
@@ -4,7 +4,9 @@ export default class NamespaceServices {
|
|
|
4
4
|
static createRootNamespace(epoch: number, name: string, duration: number, networkType: NetworkType, feeMultiplier: number): import("@tech-bureau/symbol-sdk").Transaction | null;
|
|
5
5
|
static createSubNamespace(epoch: number, name: string, parentName: string, networkType: NetworkType, feeMultiplier: number): import("@tech-bureau/symbol-sdk").Transaction | null;
|
|
6
6
|
static linkMosaic(epoch: number, namespaceId: string, mosaicId: string, networkType: NetworkType, feeMultiplier: number): AliasTransaction | null;
|
|
7
|
+
static unLinkMosaic(epoch: number, namespaceId: string, mosaicId: string, networkType: NetworkType, feeMultiplier: number): AliasTransaction | null;
|
|
7
8
|
static linkAddress(epoch: number, namespaceId: string, address: string, networkType: NetworkType, feeMultiplier: number): import("@tech-bureau/symbol-sdk").Transaction | null;
|
|
9
|
+
static unLinkAddress(epoch: number, namespaceId: string, address: string, networkType: NetworkType, feeMultiplier: number): import("@tech-bureau/symbol-sdk").Transaction | null;
|
|
8
10
|
static getNamespaceId(id: string): NamespaceId | null;
|
|
9
11
|
static getNamespace(namespaceId: string, namespaceRepository: NamespaceRepository): Promise<NamespaceInfo | null>;
|
|
10
12
|
static namespaceInfo(namespaceInfo: NamespaceInfo): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NamespaceServices.d.ts","sourceRoot":"","sources":["../../../src/service/NamespaceServices.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EAEb,gBAAgB,EAGjB,MAAM,yBAAyB,CAAA;AAGhC,MAAM,CAAC,OAAO,OAAO,iBAAiB;;IAGpC,MAAM,CAAC,mBAAmB,CACxB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAevB,MAAM,CAAC,kBAAkB,CACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAmBvB,MAAM,CAAC,UAAU,CACf,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAuBvB,MAAM,CAAC,WAAW,CAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAoBvB,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM;WAWnB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,mBAAmB;IAQvF,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,aAAa;;;;;;;;CAUlD"}
|
|
1
|
+
{"version":3,"file":"NamespaceServices.d.ts","sourceRoot":"","sources":["../../../src/service/NamespaceServices.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EAEb,gBAAgB,EAGjB,MAAM,yBAAyB,CAAA;AAGhC,MAAM,CAAC,OAAO,OAAO,iBAAiB;;IAGpC,MAAM,CAAC,mBAAmB,CACxB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAevB,MAAM,CAAC,kBAAkB,CACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAmBvB,MAAM,CAAC,UAAU,CACf,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAuBvB,MAAM,CAAC,YAAY,CACjB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAuBvB,MAAM,CAAC,WAAW,CAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAoBvB,MAAM,CAAC,aAAa,CAClB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,MAAM;IAoBvB,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM;WAWnB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,mBAAmB;IAQvF,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,aAAa;;;;;;;;CAUlD"}
|
package/package.json
CHANGED
|
@@ -87,6 +87,22 @@ describe('start namespace test', () => {
|
|
|
87
87
|
)
|
|
88
88
|
expect(mosaicLink).toBeDefined()
|
|
89
89
|
})
|
|
90
|
+
|
|
91
|
+
it('Create mosaic unlink function', () => {
|
|
92
|
+
const mosaicLink = NamespaceServices.unLinkMosaic(epoch, namespaceRawId, mosaicRawId, networkType, minFeeMultiplier)
|
|
93
|
+
expect(mosaicLink).toBeDefined()
|
|
94
|
+
})
|
|
95
|
+
it('Create account unlink function', () => {
|
|
96
|
+
const mosaicLink = NamespaceServices.unLinkAddress(
|
|
97
|
+
epoch,
|
|
98
|
+
namespaceRawId,
|
|
99
|
+
config.workAccount.address,
|
|
100
|
+
networkType,
|
|
101
|
+
minFeeMultiplier
|
|
102
|
+
)
|
|
103
|
+
expect(mosaicLink).toBeDefined()
|
|
104
|
+
})
|
|
105
|
+
|
|
90
106
|
it('Get Namespace Id function', () => {
|
|
91
107
|
const namespace = NamespaceServices.getNamespaceId(rootNamespaceName)
|
|
92
108
|
expect(namespace?.fullName).toBe(rootNamespaceName)
|
|
@@ -3,6 +3,8 @@ import rootNamespaceCreate from './rootNamespaceCreate'
|
|
|
3
3
|
import subNamespaceCreate from './subNamespaceCreate'
|
|
4
4
|
import linkMosaic from './linkMosaic'
|
|
5
5
|
import linkAddress from './linkAddress'
|
|
6
|
+
import unlinkAddress from './unlinkAddress'
|
|
7
|
+
import unlinkMosaic from './unlinkMosaic'
|
|
6
8
|
import namespaceInfo from './namespaceInfo'
|
|
7
9
|
|
|
8
10
|
const mosaic = () => {
|
|
@@ -14,6 +16,8 @@ const mosaic = () => {
|
|
|
14
16
|
program.addCommand(subNamespaceCreate)
|
|
15
17
|
program.addCommand(linkMosaic)
|
|
16
18
|
program.addCommand(linkAddress)
|
|
19
|
+
program.addCommand(unlinkAddress)
|
|
20
|
+
program.addCommand(unlinkMosaic)
|
|
17
21
|
program.addCommand(namespaceInfo)
|
|
18
22
|
|
|
19
23
|
return program
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import linkAddress from '../../infrastructure/namespace/unlinkAddress'
|
|
3
|
+
const program = new Command()
|
|
4
|
+
|
|
5
|
+
program
|
|
6
|
+
.name('unlink-address')
|
|
7
|
+
.description('Unlink Address and Announce Transaction')
|
|
8
|
+
.option('-o, --owner <work|balance|main|test1|test2|other>', 'Specify the input of from Account', 'other')
|
|
9
|
+
.option('-u, --url <mijinCatapultURL>', 'Specify the input of mijin URL')
|
|
10
|
+
.option('-n, --name <name>', 'Specify the input of Namespace Name')
|
|
11
|
+
.option('-a, --address <address>', 'Specify the input of Address')
|
|
12
|
+
.option('-r, --readfile <config.json>', 'Specify the input of Read Config File')
|
|
13
|
+
.option('-p, --privatekey <privateKey>', 'Specify the input of Mosaic Owner Account Private Key')
|
|
14
|
+
.option('-b, --bod', 'Specify the input of mijin BOD mode(use Cookie)', false)
|
|
15
|
+
.action(linkAddress)
|
|
16
|
+
|
|
17
|
+
export default program
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import linkMosaic from '../../infrastructure/namespace/unlinkMosaic'
|
|
3
|
+
const program = new Command()
|
|
4
|
+
|
|
5
|
+
program
|
|
6
|
+
.name('unlink-mosaic')
|
|
7
|
+
.description('Unlink Mosaic and Announce Transaction')
|
|
8
|
+
.option('-o, --owner <work|balance|main|test1|test2|other>', 'Specify the input of from Account', 'other')
|
|
9
|
+
.option('-u, --url <mijinCatapultURL>', 'Specify the input of mijin URL')
|
|
10
|
+
.option('-n, --name <name>', 'Specify the input of Namespace Name')
|
|
11
|
+
.option('-m, --mosaic-id <mosaic-id>', 'Specify the input of Mosaic Id')
|
|
12
|
+
.option('-r, --readfile <config.json>', 'Specify the input of Read Config File')
|
|
13
|
+
.option('-p, --privatekey <privateKey>', 'Specify the input of Mosaic Owner Account Private Key')
|
|
14
|
+
.option('-b, --bod', 'Specify the input of mijin BOD mode(use Cookie)', false)
|
|
15
|
+
.action(linkMosaic)
|
|
16
|
+
|
|
17
|
+
export default program
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import AccountServices from '../../service/AccountServices'
|
|
2
|
+
import RepositoryFactory from '../../service/RepositoryFactory'
|
|
3
|
+
import { INamespaceCreateOption } from '../../types'
|
|
4
|
+
import LoggerFactory from '../../service/Logger'
|
|
5
|
+
import { readConfig, checkFile } from '../../utils'
|
|
6
|
+
import TransactionServices from '../../service/TransactionServices'
|
|
7
|
+
import NamespaceServices from '../../service/NamespaceServices'
|
|
8
|
+
|
|
9
|
+
const logger = LoggerFactory.getLogger()
|
|
10
|
+
|
|
11
|
+
export default async (option: INamespaceCreateOption) => {
|
|
12
|
+
const { owner, url, readfile, name, address, privatekey, bod } = option
|
|
13
|
+
|
|
14
|
+
let configFile
|
|
15
|
+
|
|
16
|
+
if (readfile && (await checkFile(readfile))) {
|
|
17
|
+
configFile = await readConfig(readfile)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const mijinUrl = url ? url : configFile ? configFile.url : undefined
|
|
21
|
+
|
|
22
|
+
if (!mijinUrl) {
|
|
23
|
+
logger.error(`Must Set mijin URL(-u http://xxxxxx.com:3000) or Set Read Config(-r config.json)`)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let repo
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
repo = new RepositoryFactory(mijinUrl)
|
|
31
|
+
await repo.init(bod)
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error(`Please specify a valid URL: ${mijinUrl}`)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const networkType = repo.getNetwork()
|
|
38
|
+
const epoch = repo.getEpoch()
|
|
39
|
+
|
|
40
|
+
logger.info(`mijin URL: ${mijinUrl}`)
|
|
41
|
+
logger.info(`Network: ${networkType.toString()}`)
|
|
42
|
+
|
|
43
|
+
logger.info('Link Address...')
|
|
44
|
+
|
|
45
|
+
let createAccount
|
|
46
|
+
|
|
47
|
+
switch (owner) {
|
|
48
|
+
case 'work':
|
|
49
|
+
createAccount = configFile
|
|
50
|
+
? AccountServices.createAccount(configFile.workAccount.privateKey, networkType)
|
|
51
|
+
: undefined
|
|
52
|
+
break
|
|
53
|
+
case 'balance':
|
|
54
|
+
createAccount = configFile
|
|
55
|
+
? AccountServices.createAccount(configFile.balanceAccount.privateKey, networkType)
|
|
56
|
+
: undefined
|
|
57
|
+
break
|
|
58
|
+
case 'main':
|
|
59
|
+
createAccount = configFile
|
|
60
|
+
? AccountServices.createAccount(configFile.mainAccount.privateKey, networkType)
|
|
61
|
+
: undefined
|
|
62
|
+
break
|
|
63
|
+
case 'test1':
|
|
64
|
+
createAccount = configFile
|
|
65
|
+
? AccountServices.createAccount(configFile.test1Account.privateKey, networkType)
|
|
66
|
+
: undefined
|
|
67
|
+
break
|
|
68
|
+
case 'test2':
|
|
69
|
+
createAccount = configFile
|
|
70
|
+
? AccountServices.createAccount(configFile.test2Account.privateKey, networkType)
|
|
71
|
+
: undefined
|
|
72
|
+
break
|
|
73
|
+
default:
|
|
74
|
+
createAccount =
|
|
75
|
+
privatekey && privatekey.length === 64 ? AccountServices.createAccount(privatekey, networkType) : undefined
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!createAccount) {
|
|
80
|
+
logger.error('Create Account Not Found Set (-r config -o owner) or -p')
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!name) {
|
|
85
|
+
logger.error('Namespace name Not Found Set -n option')
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!address) {
|
|
90
|
+
logger.error('Namespace link address Not Found Set -a option')
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const minFeeMultiplier = repo.getTransactionFees().minFeeMultiplier
|
|
95
|
+
const mosaicLinkTransaction = NamespaceServices.unLinkAddress(epoch, name, address, networkType, minFeeMultiplier)
|
|
96
|
+
if (!mosaicLinkTransaction) {
|
|
97
|
+
logger.error('invalid name or address option')
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
logger.info(`Account: ${createAccount.address.plain()}`)
|
|
102
|
+
logger.info(`Namespace Name: ${name}`)
|
|
103
|
+
logger.info(`Namespace Link Address: ${address}`)
|
|
104
|
+
logger.info(`Namespace Transaction: ${JSON.stringify(mosaicLinkTransaction)}`)
|
|
105
|
+
const signedTransaction = createAccount.sign(mosaicLinkTransaction, repo.getGnerationHash())
|
|
106
|
+
|
|
107
|
+
logger.info(`Transaction Fee: ${repo.getTransactionFees().minFeeMultiplier}`)
|
|
108
|
+
logger.info('Start Announce Transaction...')
|
|
109
|
+
|
|
110
|
+
const announce = await TransactionServices.announce(
|
|
111
|
+
signedTransaction,
|
|
112
|
+
repo.createLitener(),
|
|
113
|
+
repo.createTransactionRepository(),
|
|
114
|
+
repo.createReceiptRepository()
|
|
115
|
+
).catch((err) => {
|
|
116
|
+
return err
|
|
117
|
+
})
|
|
118
|
+
if (announce instanceof Error) {
|
|
119
|
+
logger.error(`Namespace Announce ${announce}`)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
logger.info('End Transaction')
|
|
124
|
+
logger.info(`${mijinUrl}/transactionStatus/${signedTransaction.hash}`)
|
|
125
|
+
logger.info(`${mijinUrl}/transactions/confirmed/${signedTransaction.hash}`)
|
|
126
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import AccountServices from '../../service/AccountServices'
|
|
2
|
+
import RepositoryFactory from '../../service/RepositoryFactory'
|
|
3
|
+
import { INamespaceCreateOption } from '../../types'
|
|
4
|
+
import LoggerFactory from '../../service/Logger'
|
|
5
|
+
import { readConfig, checkFile } from '../../utils'
|
|
6
|
+
import TransactionServices from '../../service/TransactionServices'
|
|
7
|
+
import NamespaceServices from '../../service/NamespaceServices'
|
|
8
|
+
|
|
9
|
+
const logger = LoggerFactory.getLogger()
|
|
10
|
+
|
|
11
|
+
export default async (option: INamespaceCreateOption) => {
|
|
12
|
+
const { owner, url, readfile, name, mosaicId, privatekey, bod } = option
|
|
13
|
+
|
|
14
|
+
let configFile
|
|
15
|
+
|
|
16
|
+
if (readfile && (await checkFile(readfile))) {
|
|
17
|
+
configFile = await readConfig(readfile)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const mijinUrl = url ? url : configFile ? configFile.url : undefined
|
|
21
|
+
|
|
22
|
+
if (!mijinUrl) {
|
|
23
|
+
logger.error(`Must Set mijin URL(-u http://xxxxxx.com:3000) or Set Read Config(-r config.json)`)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let repo
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
repo = new RepositoryFactory(mijinUrl)
|
|
31
|
+
await repo.init(bod)
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error(`Please specify a valid URL: ${mijinUrl}`)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const networkType = repo.getNetwork()
|
|
38
|
+
const epoch = repo.getEpoch()
|
|
39
|
+
|
|
40
|
+
logger.info(`mijin URL: ${mijinUrl}`)
|
|
41
|
+
logger.info(`Network: ${networkType.toString()}`)
|
|
42
|
+
|
|
43
|
+
logger.info('Link Mosaic...')
|
|
44
|
+
|
|
45
|
+
let createAccount
|
|
46
|
+
|
|
47
|
+
switch (owner) {
|
|
48
|
+
case 'work':
|
|
49
|
+
createAccount = configFile
|
|
50
|
+
? AccountServices.createAccount(configFile.workAccount.privateKey, networkType)
|
|
51
|
+
: undefined
|
|
52
|
+
break
|
|
53
|
+
case 'balance':
|
|
54
|
+
createAccount = configFile
|
|
55
|
+
? AccountServices.createAccount(configFile.balanceAccount.privateKey, networkType)
|
|
56
|
+
: undefined
|
|
57
|
+
break
|
|
58
|
+
case 'main':
|
|
59
|
+
createAccount = configFile
|
|
60
|
+
? AccountServices.createAccount(configFile.mainAccount.privateKey, networkType)
|
|
61
|
+
: undefined
|
|
62
|
+
break
|
|
63
|
+
case 'test1':
|
|
64
|
+
createAccount = configFile
|
|
65
|
+
? AccountServices.createAccount(configFile.test1Account.privateKey, networkType)
|
|
66
|
+
: undefined
|
|
67
|
+
break
|
|
68
|
+
case 'test2':
|
|
69
|
+
createAccount = configFile
|
|
70
|
+
? AccountServices.createAccount(configFile.test2Account.privateKey, networkType)
|
|
71
|
+
: undefined
|
|
72
|
+
break
|
|
73
|
+
default:
|
|
74
|
+
createAccount =
|
|
75
|
+
privatekey && privatekey.length === 64 ? AccountServices.createAccount(privatekey, networkType) : undefined
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!createAccount) {
|
|
80
|
+
logger.error('Create Account Not Found Set (-r config -o owner) or -p')
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!name) {
|
|
85
|
+
logger.error('Namespace name Not Found Set -n option')
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!mosaicId) {
|
|
90
|
+
logger.error('Namespace Link Mosaic Id Not Found Set -m option')
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const minFeeMultiplier = repo.getTransactionFees().minFeeMultiplier
|
|
95
|
+
const mosaicLinkTransaction = NamespaceServices.unLinkMosaic(epoch, name, mosaicId, networkType, minFeeMultiplier)
|
|
96
|
+
if (!mosaicLinkTransaction) {
|
|
97
|
+
logger.error('invalid name or mosaic option')
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
logger.info(`Account: ${createAccount.address.plain()}`)
|
|
102
|
+
logger.info(`Namespace Name: ${name}`)
|
|
103
|
+
logger.info(`Namespace Link Mosaic Id: ${mosaicId}`)
|
|
104
|
+
logger.info(`Namespace Transaction: ${JSON.stringify(mosaicLinkTransaction)}`)
|
|
105
|
+
const signedTransaction = createAccount.sign(mosaicLinkTransaction, repo.getGnerationHash())
|
|
106
|
+
|
|
107
|
+
logger.info(`Transaction Fee: ${repo.getTransactionFees().minFeeMultiplier}`)
|
|
108
|
+
logger.info('Start Announce Transaction...')
|
|
109
|
+
|
|
110
|
+
const announce = await TransactionServices.announce(
|
|
111
|
+
signedTransaction,
|
|
112
|
+
repo.createLitener(),
|
|
113
|
+
repo.createTransactionRepository(),
|
|
114
|
+
repo.createReceiptRepository()
|
|
115
|
+
).catch((err) => {
|
|
116
|
+
return err
|
|
117
|
+
})
|
|
118
|
+
if (announce instanceof Error) {
|
|
119
|
+
logger.error(`Namespace Link Announce ${announce}`)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
logger.info('End Transaction')
|
|
124
|
+
logger.info(`${mijinUrl}/transactionStatus/${signedTransaction.hash}`)
|
|
125
|
+
logger.info(`${mijinUrl}/transactions/confirmed/${signedTransaction.hash}`)
|
|
126
|
+
}
|
|
@@ -88,6 +88,34 @@ export default class NamespaceServices {
|
|
|
88
88
|
return mosaicAliasTransaction
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
static unLinkMosaic(
|
|
92
|
+
epoch: number,
|
|
93
|
+
namespaceId: string,
|
|
94
|
+
mosaicId: string,
|
|
95
|
+
networkType: NetworkType,
|
|
96
|
+
feeMultiplier: number
|
|
97
|
+
) {
|
|
98
|
+
const namespace = this.getNamespaceId(namespaceId)
|
|
99
|
+
if (!namespace) {
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
let mosaic: MosaicId | null = null
|
|
103
|
+
try {
|
|
104
|
+
mosaic = new MosaicId(mosaicId)
|
|
105
|
+
} catch {}
|
|
106
|
+
if (!mosaic) {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
const mosaicAliasTransaction = AliasTransaction.createForMosaic(
|
|
110
|
+
Deadline.create(epoch),
|
|
111
|
+
AliasAction.Unlink,
|
|
112
|
+
namespace,
|
|
113
|
+
mosaic,
|
|
114
|
+
networkType
|
|
115
|
+
).setMaxFee(feeMultiplier) as AliasTransaction
|
|
116
|
+
return mosaicAliasTransaction
|
|
117
|
+
}
|
|
118
|
+
|
|
91
119
|
static linkAddress(
|
|
92
120
|
epoch: number,
|
|
93
121
|
namespaceId: string,
|
|
@@ -113,6 +141,31 @@ export default class NamespaceServices {
|
|
|
113
141
|
return addressAliasTransaction
|
|
114
142
|
}
|
|
115
143
|
|
|
144
|
+
static unLinkAddress(
|
|
145
|
+
epoch: number,
|
|
146
|
+
namespaceId: string,
|
|
147
|
+
address: string,
|
|
148
|
+
networkType: NetworkType,
|
|
149
|
+
feeMultiplier: number
|
|
150
|
+
) {
|
|
151
|
+
const namespace = this.getNamespaceId(namespaceId)
|
|
152
|
+
if (!namespace) {
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
if (!Address.isValidRawAddress(address)) {
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
const addressObj = Address.createFromRawAddress(address)
|
|
159
|
+
const addressAliasTransaction = AliasTransaction.createForAddress(
|
|
160
|
+
Deadline.create(epoch),
|
|
161
|
+
AliasAction.Unlink,
|
|
162
|
+
namespace,
|
|
163
|
+
addressObj,
|
|
164
|
+
networkType
|
|
165
|
+
).setMaxFee(feeMultiplier)
|
|
166
|
+
return addressAliasTransaction
|
|
167
|
+
}
|
|
168
|
+
|
|
116
169
|
static getNamespaceId(id: string) {
|
|
117
170
|
let namespaceId: NamespaceId | null = null
|
|
118
171
|
try {
|