11var fs = require ( 'fs' ) ;
2-
3- const JurisdictionContractData = require ( '../build/contracts/Jurisdiction.json' )
4- const TPLTokenContractData = require ( '../build/contracts/TPLToken.json' )
52const applicationConfig = require ( '../config.js' )
63const connectionConfig = require ( '../truffle.js' )
7-
84const connection = connectionConfig . networks [ applicationConfig . network ]
95
6+ const deployMetadataFilename = 'build/contractDeploymentAddresses.json'
7+
8+ let deployAddresses
9+ try {
10+ deployAddresses = require ( `../${ deployMetadataFilename } ` )
11+ } catch ( error ) {
12+ deployAddresses = { }
13+ }
14+
15+ let deployType = process . argv [ 2 ] // Provide Basic or Extended jurisdiction type
16+ if ( typeof ( deployType ) === 'undefined' ) {
17+ deployType = 'extended'
18+ } else {
19+ deployType = deployType . toLowerCase ( )
20+ }
21+
22+ let showAccounts = process . argv [ 3 ] // Provide if you'd like to dump accounts
23+
24+ const deployTypeOptions = new Set ( [ 'basic' , 'extended' , 'token' ] )
25+ if ( ! deployTypeOptions . has ( deployType ) ) {
26+ console . error ( 'must supply "basic", "extended", or "token" as the target!' )
27+ process . exit ( 1 )
28+ }
29+
30+ let args
31+ if ( deployType === 'token' ) {
32+ const jurisdiction = deployAddresses . jurisdiction
33+
34+ if ( typeof ( jurisdiction ) === 'undefined' ) {
35+ console . error ( 'must first deploy a jurisdiction before attaching a token!' )
36+ process . exit ( 1 )
37+ }
38+
39+ args = [
40+ applicationConfig . TPLTokenTotalSupply ,
41+ jurisdiction ,
42+ applicationConfig . TPLTokenAttributeID
43+ ]
44+ } else {
45+ args = [ ]
46+ }
47+
48+ let contractImportLocation
49+ if ( deployType === 'basic' ) {
50+ contractImportLocation = '../build/contracts/BasicJurisdiction.json'
51+ } else if ( deployType === 'extended' ) {
52+ contractImportLocation = '../build/contracts/ExtendedJurisdiction.json'
53+ } else if ( deployType === 'token' ) {
54+ contractImportLocation = '../build/contracts/TPLERC20RestrictedReceiverInstance.json'
55+ }
56+
57+ const ContractData = require ( contractImportLocation )
58+
1059let web3 = connection . provider
1160
12- const Jurisdiction = new web3 . eth . Contract ( JurisdictionContractData . abi )
13- const TPLToken = new web3 . eth . Contract ( TPLTokenContractData . abi )
14-
15- const TPLTokenAttributeID = applicationConfig . TPLTokenAttributeID
16- const TPLTokenTotalSupply = applicationConfig . TPLTokenTotalSupply
17- const TPLTokenAttributeRestricted = applicationConfig [
18- 'TPLTokenAttributeRestricted'
19- ]
20- const TPLTokenAttributeMinimumRequiredStake = applicationConfig [
21- 'TPLTokenAttributeMinimumRequiredStake'
22- ]
23- const TPLTokenAttributeJurisdictionFee = applicationConfig [
24- 'TPLTokenAttributeJurisdictionFee'
25- ]
26- const TPLTokenAttributeDescription = applicationConfig [
27- 'TPLTokenAttributeDescription'
28- ]
61+ const Contract = new web3 . eth . Contract ( ContractData . abi )
2962
3063async function main ( ) {
31- console . log ( 'deploying jurisdiction & mock TPLToken...' )
32- let deployAddresses = { }
33- const deployMetadataFilename = 'build/contractDeploymentAddresses.json'
34- const addresses = await Promise . resolve ( web3 . eth . getAccounts ( ) )
35- if ( addresses . length === 0 ) {
36- console . log ( 'cannot find any addresses...' )
37- return false
64+ console . log (
65+ `deploying ${
66+ deployType
67+ } ${
68+ deployType !== 'token' ? ' jurisdiction' : ''
69+ } to ${
70+ applicationConfig . network
71+ } network...`
72+ )
73+
74+ const accounts = await Promise . resolve ( web3 . eth . getAccounts ( ) )
75+ if ( accounts . length === 0 ) {
76+ console . error ( 'cannot find any accounts...' )
77+ process . exit ( 1 )
3878 }
3979
40- const address = addresses [ 0 ]
41- deployAddresses . owner = address
42- console . log ( ` owner: ${ address } ` )
43-
44- const JurisdictionContractInstance = await Jurisdiction . deploy ( {
45- data : JurisdictionContractData . bytecode
46- } ) . send ( {
47- from : address ,
48- gas : 5000000 ,
49- gasPrice : '1000000000'
50- } )
80+ const account = accounts [ 0 ]
81+ if ( deployType !== 'token' ) {
82+ deployAddresses . jurisdictionOwner = account
83+ } else {
84+ deployAddresses . tokenOwner = account
85+ }
86+
87+ console . log ( ` deployed by: ${ account } ` )
5188
52- const jurisdictionAddress = JurisdictionContractInstance . options . address
53- deployAddresses . jurisdiction = jurisdictionAddress
54- console . log ( ` jurisdiction: ${ jurisdictionAddress } ` )
55-
56- const TPLTokenContractInstance = await TPLToken . deploy ( {
57- data : TPLTokenContractData . bytecode ,
58- arguments : [
59- JurisdictionContractInstance . options . address ,
60- TPLTokenAttributeID ,
61- TPLTokenTotalSupply
62- ]
89+ const ContractInstance = await Contract . deploy ( {
90+ data : ContractData . bytecode ,
91+ arguments : args
6392 } ) . send ( {
64- from : address ,
65- gas : 5000000 ,
66- gasPrice : '1000000000 '
93+ from : account ,
94+ gas : 7000000 ,
95+ gasPrice : '10000000000 '
6796 } )
6897
69- const tokenAddress = TPLTokenContractInstance . options . address
70- deployAddresses . token = tokenAddress
71- console . log ( `mock TPL token: ${ tokenAddress } ` )
98+ const deployedAddress = ContractInstance . options . address
99+ if ( deployType !== 'token' ) {
100+ deployAddresses . jurisdiction = deployedAddress
101+ console . log ( ` jurisdiction: ${ deployedAddress } ` )
102+ } else {
103+ deployAddresses . token = deployedAddress
104+ console . log ( ` mock token: ${ deployedAddress } ` )
105+ }
72106
73107 fs . writeFile (
74108 deployMetadataFilename ,
@@ -77,10 +111,14 @@ async function main() {
77111 err => {
78112 if ( err ) {
79113 console . error ( err )
80- process . exit ( )
114+ process . exit ( 1 )
81115 }
82116 console . log ( `metadata written to ${ deployMetadataFilename } ` )
83- process . exit ( )
117+ if ( showAccounts === 'verbose' ) {
118+ console . log ( )
119+ console . log ( JSON . stringify ( deployAddresses , null , 2 ) )
120+ }
121+ process . exit ( 0 )
84122 }
85123 )
86124}
0 commit comments