Skip to content

Commit f4c2204

Browse files
committed
update with adjustments
1 parent 91415bb commit f4c2204

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

src/utils/cspr-network.ts

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CasperNetwork {
4343
amountMotes: string | BigNumber,
4444
deployCost: number,
4545
ttl: number,
46-
contractHash?: string
46+
auctionContractHash?: string
4747
) {
4848
if (this.apiVersion === 2) {
4949
new NativeDelegateBuilder()
@@ -56,10 +56,10 @@ export class CasperNetwork {
5656
.build();
5757
}
5858

59-
if (contractHash) {
59+
if (auctionContractHash) {
6060
return new ContractCallBuilder()
6161
.from(delegatorPublicKey)
62-
.byHash(contractHash)
62+
.byHash(auctionContractHash)
6363
.entryPoint('delegate')
6464
.chainName(networkName)
6565
.runtimeArgs(
@@ -73,7 +73,9 @@ export class CasperNetwork {
7373
.buildFor1_5();
7474
}
7575

76-
return new Error('Need to provide contract hash');
76+
return new Error(
77+
'Auction contract hash is required when creating a transaction on Casper Network 1.5.x'
78+
);
7779
}
7880

7981
public createUndelegateTransaction(
@@ -83,7 +85,7 @@ export class CasperNetwork {
8385
amountMotes: string | BigNumber,
8486
deployCost: number,
8587
ttl: number,
86-
contractHash?: string
88+
auctionContractHash?: string
8789
) {
8890
if (this.apiVersion === 2) {
8991
new NativeUndelegateBuilder()
@@ -96,10 +98,10 @@ export class CasperNetwork {
9698
.build();
9799
}
98100

99-
if (contractHash) {
101+
if (auctionContractHash) {
100102
return new ContractCallBuilder()
101103
.from(delegatorPublicKey)
102-
.byHash(contractHash)
104+
.byHash(auctionContractHash)
103105
.entryPoint('undelegate')
104106
.chainName(networkName)
105107
.ttl(ttl)
@@ -113,21 +115,25 @@ export class CasperNetwork {
113115
.buildFor1_5();
114116
}
115117

116-
return new Error('Need to provide contract hash');
118+
return new Error(
119+
'Auction contract hash is required when creating a transaction on Casper Network 1.5.x'
120+
);
117121
}
118122

119123
public createRedelegateTransaction(
120124
delegatorPublicKey: PublicKey,
121125
validatorPublicKey: PublicKey,
126+
newValidatorPublicKey: PublicKey,
122127
networkName: string,
123128
amountMotes: string | BigNumber,
124129
deployCost: number,
125130
ttl: number,
126-
contractHash?: string
131+
auctionContractHash?: string
127132
) {
128133
if (this.apiVersion === 2) {
129134
new NativeRedelegateBuilder()
130135
.validator(validatorPublicKey)
136+
.newValidator(newValidatorPublicKey)
131137
.from(delegatorPublicKey)
132138
.amount(amountMotes)
133139
.chainName(networkName)
@@ -136,21 +142,31 @@ export class CasperNetwork {
136142
.build();
137143
}
138144

139-
if (contractHash) {
140-
// need to provide contract hash
141-
return (
142-
new ContractCallBuilder()
143-
.from(delegatorPublicKey)
144-
.byHash(contractHash)
145-
.entryPoint('redelegate')
146-
.chainName(networkName)
147-
// .amount(amountMotes)
148-
.ttl(ttl)
149-
.buildFor1_5()
150-
);
145+
if (auctionContractHash) {
146+
return new ContractCallBuilder()
147+
.from(delegatorPublicKey)
148+
.byHash(auctionContractHash)
149+
.entryPoint('redelegate')
150+
.chainName(networkName)
151+
.runtimeArgs(
152+
Args.fromMap({
153+
validator: CLValue.newCLPublicKey(validatorPublicKey),
154+
delegator: CLValue.newCLPublicKey(delegatorPublicKey),
155+
amount: CLValueUInt512.newCLUInt512(amountMotes),
156+
...(newValidatorPublicKey
157+
? {
158+
new_validator: CLValue.newCLPublicKey(newValidatorPublicKey)
159+
}
160+
: {})
161+
})
162+
)
163+
.ttl(ttl)
164+
.buildFor1_5();
151165
}
152166

153-
return new Error('Need to provide contract hash');
167+
return new Error(
168+
'Auction contract hash is required when creating a transaction on Casper Network 1.5.x'
169+
);
154170
}
155171

156172
public createTransferTransaction(
@@ -185,7 +201,9 @@ export class CasperNetwork {
185201
return await this.rpcClient.putDeploy(deploy);
186202
}
187203

188-
return Promise.reject('Transaction does not have a deploy');
204+
return Promise.reject(
205+
'Legacy deploy transaction is required when submitting to Casper Network 1.5'
206+
);
189207
}
190208

191209
public async getTransaction(hash: TransactionHash) {
@@ -195,12 +213,16 @@ export class CasperNetwork {
195213
hash.transactionV1?.toHex()
196214
);
197215
}
216+
217+
if (hash.deploy) {
218+
return await this.rpcClient.getTransactionByDeployHash(
219+
hash.deploy.toHex()
220+
);
221+
}
198222
}
199223

200224
if (hash.deploy) {
201-
return await this.rpcClient.getTransactionByDeployHash(
202-
hash.deploy.toHex()
203-
);
225+
return await this.rpcClient.getDeploy(hash.deploy.toHex());
204226
}
205227

206228
return Promise.reject('Hash is not valid');

0 commit comments

Comments
 (0)