Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/setup-node…
Browse files Browse the repository at this point in the history
…-4.0.3
  • Loading branch information
agadzhalov authored Aug 6, 2024
2 parents f5f60cd + c0e092d commit fdd5316
Show file tree
Hide file tree
Showing 38 changed files with 3,210 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: true

Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/common_js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: true

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defaults:
permissions:
pages: write
contents: read
id-token: write

jobs:
build-and-deploy-docs:
Expand All @@ -23,7 +24,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: ${{ github.event.inputs.tag || '' }}
fetch-depth: 0
Expand Down Expand Up @@ -235,7 +235,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: ${{ github.event.inputs.tag || '' }}

Expand Down Expand Up @@ -271,7 +271,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: ${{ github.event.inputs.tag || '' }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/react_native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup Java
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup Java
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/renovate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: recursive

Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v2.49.2

## What's Changed

* fix: update taskfile status check for submodules task by @isavov in https://github.com/hashgraph/hedera-sdk-js/pull/2435
* chore: fix token permissions for deploy to github pages by @isavov in https://github.com/hashgraph/hedera-sdk-js/pull/2418
* fix: reconnect to working node by @0xivanov in https://github.com/hashgraph/hedera-sdk-js/pull/2417
* release: proto v2.15.0-beta.3 by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2415
* update: add node id to the precheck error by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2414
* feat: Implement TokenRejectTransaction by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2411
* update: handle PLATFORM_NOT_ACTIVE error gracefully by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2401
* feat: pull protobuf changes from latest tag by @isavov in https://github.com/hashgraph/hedera-sdk-js/pull/2435
* chore: fix token permissions for deploy to github pages by @isavov in https://github.com/hashgraph/hedera-sdk-js/pull/2389
* update: release all skipped tests by @svetoslav-nikol0v in https://github.com/hashgraph/hedera-sdk-js/pull/2395
* test: add maxAutomaticTokenAssociations tests by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2390

## v2.48.1

## What's Changed
Expand Down
6 changes: 3 additions & 3 deletions examples/react-native-example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3779,9 +3779,9 @@ fast-glob@^3.2.5, fast-glob@^3.2.9:
micromatch "^4.0.4"

fast-loops@^1.1.3:
version "1.1.3"
resolved "https://registry.npmjs.org/fast-loops/-/fast-loops-1.1.3.tgz"
integrity sha512-8EZzEP0eKkEEVX+drtd9mtuQ+/QrlfW/5MlwcwK5Nds6EkZ/tRzEexkzUY2mIssnAyVLT+TKHuRXmFNNXYUd6g==
version "1.1.4"
resolved "https://registry.yarnpkg.com/fast-loops/-/fast-loops-1.1.4.tgz#61bc77d518c0af5073a638c6d9d5c7683f069ce2"
integrity sha512-8dbd3XWoKCTms18ize6JmQF1SFnnfj5s0B7rRry22EofgMu7B6LKHVh+XfFqFGsqnbH54xgeO83PzpKI+ODhlg==

fast-redact@^3.1.1:
version "3.3.0"
Expand Down
241 changes: 241 additions & 0 deletions examples/token-reject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import {
AccountCreateTransaction,
PrivateKey,
TokenCreateTransaction,
TransferTransaction,
AccountId,
Client,
TokenType,
TokenMintTransaction,
TokenRejectTransaction,
TokenRejectFlow,
NftId,
AccountBalanceQuery,
TokenSupplyType,
} from "@hashgraph/sdk";
import dotenv from "dotenv";

dotenv.config();

async function main() {
if (
process.env.OPERATOR_ID == null ||
process.env.OPERATOR_KEY == null ||
process.env.HEDERA_NETWORK == null
) {
throw new Error(
"Environment variables OPERATOR_ID, HEDERA_NETWORK, and OPERATOR_KEY are required.",
);
}
const CID = [
"QmNPCiNA3Dsu3K5FxDPMG5Q3fZRwVTg14EXA92uqEeSRXn",
"QmZ4dgAgt8owvnULxnKxNe8YqpavtVCXmc1Lt2XajFpJs9",
"QmPzY5GxevjyfMUF5vEAjtyRoigzWp47MiKAtLBduLMC1T",
];
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromStringED25519(process.env.OPERATOR_KEY);
const network = process.env.HEDERA_NETWORK;
const client = Client.forName(network).setOperator(operatorId, operatorKey);

// create a treasury account
const treasuryPrivateKey = PrivateKey.generateED25519();
const treasuryAccountId = (
await (
await new AccountCreateTransaction()
.setKey(treasuryPrivateKey)
.setMaxAutomaticTokenAssociations(100)
.execute(client)
).getReceipt(client)
).accountId;

// create a receiver account with unlimited max auto associations
const receiverPrivateKey = PrivateKey.generateED25519();
const receiverAccountId = (
await (
await new AccountCreateTransaction()
.setKey(receiverPrivateKey)
.setMaxAutomaticTokenAssociations(-1)
.execute(client)
).getReceipt(client)
).accountId;

// create a nft collection
const nftCreationTx = await (
await new TokenCreateTransaction()
.setTokenType(TokenType.NonFungibleUnique)
.setTokenName("Example Fungible Token")
.setTokenSymbol("EFT")
.setMaxSupply(CID.length)
.setSupplyType(TokenSupplyType.Finite)
.setSupplyKey(operatorKey)
.setAdminKey(operatorKey)
.setTreasuryAccountId(treasuryAccountId)
.freezeWith(client)
.sign(treasuryPrivateKey)
).execute(client);

const nftId = (await nftCreationTx.getReceipt(client)).tokenId;
console.log("NFT ID: ", nftId.toString());

// create a fungible token
const ftCreationTx = await (
await new TokenCreateTransaction()
.setTokenName("Example Fungible Token")
.setTokenSymbol("EFT")
.setInitialSupply(100000000)
.setSupplyKey(operatorKey)
.setAdminKey(operatorKey)
.setTreasuryAccountId(treasuryAccountId)
.freezeWith(client)
.sign(treasuryPrivateKey)
).execute(client);

const ftId = (await ftCreationTx.getReceipt(client)).tokenId;
console.log("FT ID: ", ftId.toString());

// mint 3 NFTs to treasury
const nftSerialIds = [];
for (let i = 0; i < CID.length; i++) {
const { serials } = await (
await new TokenMintTransaction()
.setTokenId(nftId)
.addMetadata(Buffer.from(CID[i]))
.execute(client)
).getReceipt(client);
const [serial] = serials;
nftSerialIds.push(new NftId(nftId, serial));
}

// transfer nfts to receiver
await (
await (
await new TransferTransaction()
.addNftTransfer(
nftSerialIds[0],
treasuryAccountId,
receiverAccountId,
)
.addNftTransfer(
nftSerialIds[1],
treasuryAccountId,
receiverAccountId,
)
.addNftTransfer(
nftSerialIds[2],
treasuryAccountId,
receiverAccountId,
)
.freezeWith(client)
.sign(treasuryPrivateKey)
).execute(client)
).getReceipt(client);

// transfer fungible tokens to receiver
await (
await (
await new TransferTransaction()
.addTokenTransfer(ftId, treasuryAccountId, -1)
.addTokenTransfer(ftId, receiverAccountId, 1)
.freezeWith(client)
.sign(treasuryPrivateKey)
).execute(client)
).getReceipt(client);

console.log("=======================");
console.log("Before Token Reject");
console.log("=======================");
const receiverFTBalanceBefore = (
await new AccountBalanceQuery()
.setAccountId(receiverAccountId)
.execute(client)
).tokens.get(ftId);
const treasuryFTBalanceBefore = (
await new AccountBalanceQuery()
.setAccountId(treasuryAccountId)
.execute(client)
).tokens.get(ftId);
const receiverNFTBalanceBefore = (
await new AccountBalanceQuery()
.setAccountId(receiverAccountId)
.execute(client)
).tokens.get(nftId);
const treasuryNFTBalanceBefore = (
await new AccountBalanceQuery()
.setAccountId(treasuryAccountId)
.execute(client)
).tokens.get(nftId);
console.log("Receiver FT balance: ", receiverFTBalanceBefore.toInt());
console.log("Treasury FT balance: ", treasuryFTBalanceBefore.toInt());
console.log(
"Receiver NFT balance: ",
receiverNFTBalanceBefore ? receiverNFTBalanceBefore.toInt() : 0,
);
console.log("Treasury NFT balance: ", treasuryNFTBalanceBefore.toInt());

// reject fungible tokens back to treasury
const tokenRejectResponse = await (
await (
await new TokenRejectTransaction()
.setOwnerId(receiverAccountId)
.addTokenId(ftId)
.freezeWith(client)
.sign(receiverPrivateKey)
).execute(client)
).getReceipt(client);

// reject NFTs back to treasury
const rejectFlowResponse = await (
await (
new TokenRejectFlow()
.setOwnerId(receiverAccountId)
.setNftIds(nftSerialIds)
.freezeWith(client)
.sign(receiverPrivateKey)
).execute(client)
).getReceipt(client);

const tokenRejectStatus = tokenRejectResponse.status.toString();
const tokenRejectFlowStatus = rejectFlowResponse.status.toString();

console.log("=======================");
console.log("After Token Reject Transaction and flow");
console.log("=======================");

const receiverFTBalanceAfter = (
await new AccountBalanceQuery()
.setAccountId(receiverAccountId)
.execute(client)
).tokens.get(ftId);

const treasuryFTBalanceAfter = (
await new AccountBalanceQuery()
.setAccountId(treasuryAccountId)
.execute(client)
).tokens.get(ftId);

const receiverNFTBalanceAfter = (
await new AccountBalanceQuery()
.setAccountId(receiverAccountId)
.execute(client)
).tokens.get(nftId);

const treasuryNFTBalanceAfter = (
await new AccountBalanceQuery()
.setAccountId(treasuryAccountId)
.execute(client)
).tokens.get(nftId);

console.log("TokenReject response:", tokenRejectStatus);
console.log("TokenRejectFlow response:", tokenRejectFlowStatus);
console.log("Receiver FT balance: ", receiverFTBalanceAfter.toInt());
console.log("Treasury FT balance: ", treasuryFTBalanceAfter.toInt());
console.log(
"Receiver NFT balance: ",
receiverNFTBalanceAfter ? receiverNFTBalanceAfter.toInt() : 0,
);
console.log("Treasury NFT balance: ", treasuryNFTBalanceAfter.toInt());

client.close();
}

void main();
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/sdk",
"version": "2.48.1",
"version": "2.49.2",
"description": "Hedera™ Hashgraph SDK",
"types": "./lib/index.d.ts",
"main": "./lib/index.cjs",
Expand Down Expand Up @@ -58,7 +58,7 @@
"@ethersproject/rlp": "^5.7.0",
"@grpc/grpc-js": "1.8.2",
"@hashgraph/cryptography": "1.4.8-beta.5",
"@hashgraph/proto": "2.15.0-beta.2",
"@hashgraph/proto": "2.15.0-beta.3",
"axios": "^1.6.4",
"bignumber.js": "^9.1.1",
"bn.js": "^5.1.1",
Expand Down
Loading

0 comments on commit fdd5316

Please sign in to comment.