This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
95 lines (87 loc) · 2.95 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const Yamljs = require('yamljs')
const deployment = Yamljs.load('./deployment.yaml')
const serverAddress = deployment.server_address
const Web3 = require('web3')
const web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider(deployment.protocol + '://' + deployment.host + ':' + deployment.port))
const Readline = require('readline')
const readline = Readline.createInterface({
input: process.stdin,
output: process.stdout
})
const smartSubscAbi = require('./build/contracts/SmartSubsc.json').abi
const smartSubscContract = new web3.eth.Contract(smartSubscAbi, deployment.SmartSubsc_address, {
gas: deployment.gas,
gasPrice: deployment.gasPrice
})
console.log('The server is supported to execute the following functions:')
console.log('1. updatePrice')
console.log('2. updateServiceFeeRate')
console.log('3. activateSubscription')
console.log('4. expireSubscription')
console.log('Type something else to exit.')
readline.question('What is the number corresponding to the function to be executed?\n', number => {
switch (number) {
case '1':
excuteUpdatePrice()
break
case '2':
excuteUpdateServiceFeeRate()
break
case '3':
excuteActivateSubscription()
break
case '4':
excuteExpireSubscription()
break
default:
console.log('The server will exit...')
process.exit()
}
})
function excuteUpdatePrice() {
readline.question('What is the price to be set in ETH?\n', _price => {
smartSubscContract.methods.updatePrice(web3.utils.toWei(_price, "ether")).send({
from: serverAddress
}).then(receipt => {
console.log(receipt)
})
readline.close()
})
}
function excuteUpdateServiceFeeRate() {
readline.question('What is the service fee rate to be set in %?\n', _serviceFeeRate => {
smartSubscContract.methods.updateServiceFeeRate(_serviceFeeRate).send({
from: serverAddress
}).then(receipt => {
console.log(receipt)
})
readline.close()
})
}
function excuteActivateSubscription() {
let _tokenId
readline.question('What is the address of the owner?\n', _owner => {
readline.question('What is the ID of the token?\n', tokenId => {
_tokenId = Number(tokenId)
smartSubscContract.methods.activateSubscription(_owner, _tokenId).send({
from: serverAddress
}).then(receipt => {
console.log(receipt)
})
readline.close()
})
})
}
function excuteExpireSubscription() {
let _tokenId
readline.question('What is the ID of the token?\n', tokenId => {
_tokenId = Number(tokenId)
smartSubscContract.methods.expireSubscription(_tokenId).send({
from: serverAddress
}).then(receipt => {
console.log(receipt)
})
readline.close()
})
}