forked from ar-io/testnet-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-gateway-settings.ts
109 lines (95 loc) · 3.3 KB
/
update-gateway-settings.ts
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { Gateway } from '@ar.io/sdk';
import { JWKInterface } from 'arweave/node/lib/wallet';
import inquirer from 'inquirer';
import { IOState } from '../../src/types';
import {
arnsContractTxId,
arweave,
getContractManifest,
initialize,
loadWallet,
networkContract,
warp,
} from '../utilities';
import questions from './questions';
(async () => {
// simple setup script
initialize();
// Get the key file used for the distribution
const wallet: JWKInterface = loadWallet();
const walletAddress = await arweave.wallets.jwkToAddress(wallet);
const existingGatewayDetails: Gateway | undefined =
await networkContract.getGateway({
address: walletAddress,
});
if (!existingGatewayDetails) {
console.error('Gateway not found with address:', walletAddress);
return;
}
const gatewayDetails = await inquirer.prompt(
questions.gatewaySettings(walletAddress, existingGatewayDetails),
);
// get contract manifest
const { evaluationOptions = {} } = await getContractManifest({
contractTxId: arnsContractTxId,
});
// Connect the ArNS Registry Contract
const contract = await warp
.contract<IOState>(arnsContractTxId)
.connect(wallet)
.setEvaluationOptions(evaluationOptions)
.syncState(`https://api.arns.app/v1/contract/${arnsContractTxId}`, {
validity: true,
});
const confirm = await inquirer.prompt({
name: 'confirm',
type: 'confirm',
message: `CONFIRM UPDATED GATEWAY DETAILS? ${JSON.stringify(
gatewayDetails,
)} >`,
});
if (confirm.confirm) {
const payload = {
function: 'updateGatewaySettings',
...(gatewayDetails.observerWallet
? { observerWallet: gatewayDetails.observerWallet }
: {}),
...(gatewayDetails.allowDelegatedStaking
? { allowDelegatedStaking: gatewayDetails.allowDelegatedStaking }
: {}),
...(gatewayDetails.delegateRewardShareRatio
? {
delegateRewardShareRatio: gatewayDetails.delegateRewardShareRatio,
}
: {}),
...(gatewayDetails.autoStake
? { autoStake: gatewayDetails.autoStake }
: {}),
...(gatewayDetails.minDelegatedStake
? { minDelegatedStake: gatewayDetails.minDelegatedStake }
: {}),
...(gatewayDetails.note ? { note: gatewayDetails.note } : {}),
...(gatewayDetails.properties
? { properties: gatewayDetails.properties }
: {}),
...(gatewayDetails.protocol ? { protocol: gatewayDetails.protocol } : {}),
...(gatewayDetails.port ? { port: gatewayDetails.port } : {}),
...(gatewayDetails.fqdn ? { fqdn: gatewayDetails.fqdn } : {}),
...(gatewayDetails.label ? { label: gatewayDetails.label } : {}),
// note: removing qty from the payload as it's not a valid field for updateGatewaySettings
};
const dryWrite = await contract.dryWrite(payload);
if (dryWrite.type === 'error' || dryWrite.errorMessage) {
console.error('Failed to update gateway:', dryWrite.errorMessage);
return;
}
console.log('Submitting transaction to update gateway...');
const txId = await contract.writeInteraction(payload, {
disableBundling: true,
});
// eslint-disable-next-line
console.log(
`Successfully submitted request to update gateway. TxId: ${txId?.originalTxId}`,
);
}
})();