Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Update Token #194

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b87adbc
CI/CD: Enable ESLint Github Action (#104)
poi-son-ivy Feb 21, 2024
982bd26
CI/CD : Adding Snap Unit Test Github Action (#105)
poi-son-ivy Feb 22, 2024
12d668b
Create token api (#106)
himalayan-dev Feb 22, 2024
44ba23a
Merge branch 'main' into dev
kpachhai Feb 22, 2024
e75f278
Refactor: Extract Utils From Snap (#108)
poi-son-ivy Feb 23, 2024
977df63
Fix nft transfer (#114)
himalayan-dev Feb 26, 2024
ca99cb2
Updated version number (#115)
himalayan-dev Feb 26, 2024
7cbacf1
Docs: README Update (#110)
poi-son-ivy Feb 26, 2024
9934044
Fix display of addresses (#117)
himalayan-dev Feb 27, 2024
667275b
Refactor: Snap State and Account Static Classes (#111)
poi-son-ivy Feb 27, 2024
6e6723b
Refactor: Command / Facade / Strategy Design Patterns (#121)
poi-son-ivy Mar 7, 2024
8045d7d
API: Adding Dissociate Token API (#123)
poi-son-ivy Mar 11, 2024
66b2542
Added hts/mintToken API (#126)
himalayan-dev Mar 11, 2024
0cc80ba
Added a new API for burning a token (#127)
himalayan-dev Mar 11, 2024
82af30e
moved token commands to subfolder / added DeleteTokenCommand
poi-son-ivy Mar 12, 2024
4906589
moved token facades into subdir
poi-son-ivy Mar 12, 2024
8ddd305
added delete token facade, index.ts method, delete token params and c…
poi-son-ivy Mar 12, 2024
788cb3b
prettier fix
poi-son-ivy Mar 12, 2024
5ff842f
Fixed license headers (#129)
himalayan-dev Mar 12, 2024
6a4118d
Feat/wipe token (#130)
himalayan-dev Mar 12, 2024
ec19741
Added two new APIs for freezing/unfreezing account for a token (#131)
himalayan-dev Mar 12, 2024
2a0b715
added demo card for deleting a token
poi-son-ivy Mar 12, 2024
2219c2e
Merge branch 'wallet-snap-dev' of https://github.com/hashgraph/hedera…
poi-son-ivy Mar 12, 2024
afd1ad2
copyright header fix
poi-son-ivy Mar 12, 2024
88f4ec8
changed delete token parameter validation to use checkValidString
poi-son-ivy Mar 12, 2024
c5ca31a
added types / command for update token, also added utility function t…
poi-son-ivy Mar 14, 2024
9a1276d
update token facade + changes for including tokenid
poi-son-ivy Mar 14, 2024
c6bffcc
updated validation functions to include update token
poi-son-ivy Mar 14, 2024
7e7ef45
created site components for update token
poi-son-ivy Mar 15, 2024
5ecf375
picked out a few create/update copy/paste issues, added the remaining…
poi-son-ivy Mar 15, 2024
1d6af95
added update fee schedule command, removed eslint ignore that is no l…
poi-son-ivy Mar 15, 2024
a6a9f97
grouped commands / facades together, just about done with incorporati…
poi-son-ivy Mar 15, 2024
6120295
added UpdateTokenFeeScheduleFacade and changed in RPC router
poi-son-ivy Mar 15, 2024
c9607ea
added UpdateTokenFeeScheduleFacade and changed in RPC router but actu…
poi-son-ivy Mar 15, 2024
907a4e8
refactored updating token fee schedules to a separate API / added a g…
poi-son-ivy Mar 18, 2024
413cd31
comments on why we need to mock the window.location.href global
poi-son-ivy Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added update fee schedule command, removed eslint ignore that is no l…
…onger needed

Signed-off-by: Ivy Astrix <ivy.astrix@gmail.com>
poi-son-ivy committed Mar 15, 2024
commit 1d6af95d5a891fc5c6a10f3bc437afa552f270ed
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
*
*/

/* eslint-disable @typescript-eslint/unbound-method */

import {
Client,
PrivateKey,
@@ -31,12 +29,9 @@ import { TxReceipt } from '../../types/hedera';
import { Utils } from '../../utils/Utils';

export class UpdateTokenCommand {
readonly #tokenId: string;

readonly #adminKey: PrivateKey;

constructor(tokenId: string, adminKey: PrivateKey) {
this.#tokenId = tokenId;
constructor(adminKey: PrivateKey) {
this.#adminKey = adminKey;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*-
*
* Hedera Wallet Snap
*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import {
Client,
CustomFixedFee,
Hbar,
PrivateKey,
TokenFeeScheduleUpdateTransaction,
} from '@hashgraph/sdk';
import { TokenCustomFee } from '../../types/params';
import { TxReceipt } from '../../types/hedera';
import { Utils } from '../../utils/Utils';

export class UpdateTokenFeeScheduleCommand {
readonly #tokenId: string;

readonly #feeScheduleKey: PrivateKey;

readonly #decimals: number;

readonly #customFees: TokenCustomFee[];

constructor(
tokenId: string,
feeScheduleKey: PrivateKey,
decimals: number,
customFees: TokenCustomFee[],
) {
this.#tokenId = tokenId;
this.#feeScheduleKey = feeScheduleKey;
this.#decimals = decimals;
this.#customFees = customFees;
}

public async execute(client: Client): Promise<TxReceipt> {
const transaction = new TokenFeeScheduleUpdateTransaction()
.setTokenId(this.#tokenId)
.setCustomFees(this.#convertCustomFees(this.#customFees, this.#decimals))
.freezeWith(client);

const signedTx = await transaction.sign(this.#feeScheduleKey);
const txResponse = await signedTx.execute(client);
const receipt = await txResponse.getReceipt(client);

return Utils.formatTransactionReceipt(receipt);
}

#convertCustomFees(
customTokenFees: TokenCustomFee[],
decimals: number,
): CustomFixedFee[] {
const customFees: CustomFixedFee[] = customTokenFees.map(
(tokenCustomFee: TokenCustomFee) => {
const customFee = new CustomFixedFee({
feeCollectorAccountId: tokenCustomFee.feeCollectorAccountId,
});
if (tokenCustomFee.hbarAmount) {
customFee.setHbarAmount(new Hbar(tokenCustomFee.hbarAmount));
}
if (tokenCustomFee.tokenAmount) {
customFee.setAmount(
tokenCustomFee.tokenAmount * Math.pow(10, decimals),
);
}
if (tokenCustomFee.denominatingTokenId) {
customFee.setDenominatingTokenId(tokenCustomFee.denominatingTokenId);
}
if (tokenCustomFee.allCollectorsAreExempt) {
customFee.setAllCollectorsAreExempt(
tokenCustomFee.allCollectorsAreExempt,
);
}
return customFee;
},
);
return customFees;
}
}
Original file line number Diff line number Diff line change
@@ -162,3 +162,9 @@ export type UpdateTokenRequestParams = {
autoRenewAccountId?: string;
autoRenewPeriod?: number;
};

export type UpdateFeeScheduleRequestParams = {
tokenId: string;
feeSchedulePublicKey: string;
customFees: TokenCustomFee[];
};