Skip to content

Commit

Permalink
Merge branch 'main' into feat/tck-update-accounts-transactions
Browse files Browse the repository at this point in the history
Signed-off-by: ivaylogarnev-limechain <[email protected]>
  • Loading branch information
ivaylogarnev-limechain committed Dec 16, 2024
2 parents b5f2192 + 650744c commit 190b836
Show file tree
Hide file tree
Showing 38 changed files with 39,917 additions and 5,869 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
id: start-local-node
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
run: |
${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d -—network local --balance=100000
${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d -—network local --balance=100000 --network-tag=0.57.0
# Wait for the network to fully start
sleep 30
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'PR Formatting'
on:
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- edited
- synchronize

defaults:
run:
shell: bash

permissions:
contents: read

concurrency:
group: pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
title-check:
name: Title Check
runs-on: client-sdk-linux-medium
if: ${{ !github.event.pull_request.base.repo.fork }}
permissions:
statuses: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- name: Check PR Title
uses: step-security/conventional-pr-title-action@19fb561b33015fd2184055a05ce5a3bcf2ba3f54 # v3.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/renovate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
submodules: recursive

- name: Self-hosted Renovate
uses: renovatebot/github-action@936628dfbff213ab2eb95033c5e123cfcaf09ebb # v41.0.5
uses: renovatebot/github-action@e3a862510f27d57a380efb11f0b52ad7e8dbf213 # v41.0.6
with:
configurationFile: .github/renovate.json
token: ${{ secrets.RENOVATE_TOKEN }}
26 changes: 24 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,34 @@ 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.55.1

## What's Changed

* feat: update \_makeTransactionData of NodeUpdateTransaction by @SvetBorislavov in https://github.com/hashgraph/hedera-sdk-js/pull/2658
* chore: update protobufs by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/265

## v2.55.0

## What's Changed

* feat: Added InvalidNode check in the Executable by @ivaylogarnev-limechain in https://github.com/hashgraph/hedera-sdk-js/pull/2661
* feat: Pull protos from services by @ivaylogarnev-limechain in https://github.com/hashgraph/hedera-sdk-js/pull/2611
* fix: Protobufs updated by @ivaylogarnev-limechain in https://github.com/hashgraph/hedera-sdk-js/pull/2691
* fix: typescript issue with long by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2692
* fix: rework examples by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2646
* chore: replace pnpm/action-setup with a step-security maintained one by @PavelSBorisov in https://github.com/hashgraph/hedera-sdk-js/pull/2676
* docs: fix readme by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2685
* ci: Issues with codecov upload by @san-est in https://github.com/hashgraph/hedera-sdk-js/pull/2684
* ci: add pr title check workflow to ensure conventional commits by @PavelSBorisov in https://github.com/hashgraph/hedera-sdk-js/pull/2661


## v2.55.0-beta.1

## What's Changed

* feat: Pull protos from services @ivaylogarnev-limechain in https://github.com/hashgraph/hedera-sdk-js/pull/2611
* fix: rework examples y @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2646
* feat: Pull protos from services by @ivaylogarnev-limechain in https://github.com/hashgraph/hedera-sdk-js/pull/2611
* fix: rework examples by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2646
* docs: fix readme by @ivaylonikolov7 in https://github.com/hashgraph/hedera-sdk-js/pull/2685
* chore: replace pnpm/action-setup with a step-security maintained one by @PavelSBorisov in https://github.com/hashgraph/hedera-sdk-js/pull/2676
* ci: Issues with codecov upload by @san-est in https://github.com/hashgraph/hedera-sdk-js/pull/2684
Expand Down
209 changes: 209 additions & 0 deletions examples/long-term-schedule-transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import {
Client,
AccountCreateTransaction,
Hbar,
PrivateKey,
KeyList,
TransferTransaction,
ScheduleSignTransaction,
ScheduleInfoQuery,
AccountBalanceQuery,
AccountUpdateTransaction,
Timestamp,
} 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.",
);
}

console.log("Long Term Scheduled Transaction Example Start!");

// Step 0: Create and configure the SDK Client.
const operatorId = process.env.OPERATOR_ID;
const operatorKey = PrivateKey.fromStringED25519(process.env.OPERATOR_KEY);
const client = Client.forName(process.env.HEDERA_NETWORK || "testnet");
client.setOperator(operatorId, operatorKey);

// Step 1: Create key pairs
const privateKey1 = PrivateKey.generateED25519();
const privateKey2 = PrivateKey.generateED25519();
const thresholdKey = new KeyList([
privateKey1.publicKey,
privateKey2.publicKey,
]);
console.log("Created a Key List: ", thresholdKey);

// Step 2: Create the account
console.log("Creating new account...");
const aliceId = (
await (
await new AccountCreateTransaction()
.setKey(thresholdKey)
.setInitialBalance(new Hbar(2))
.execute(client)
).getReceipt(client)
).accountId;
console.log("Created new account with ID: ", aliceId.toString());

// Step 3: Schedule a transfer transaction
console.log("Creating new scheduled transaction with 1 day expiry");
const transfer = new TransferTransaction()
.addHbarTransfer(aliceId, new Hbar(-1))
.addHbarTransfer(client.operatorAccountId, new Hbar(1));
const hasJitter = false;

const scheduleId = (
await (
await transfer
.schedule()
.setWaitForExpiry(false)
.setExpirationTime(
Timestamp.generate(hasJitter).plusNanos(
86400 * 1_000_000_000,
),
) // 1 day in milliseconds
.execute(client)
).getReceipt(client)
).scheduleId;

// Step 4: Sign the transaction with one key
console.log("Signing the new scheduled transaction with 1 key");
await (
await (
await new ScheduleSignTransaction()
.setScheduleId(scheduleId)
.freezeWith(client)
.sign(privateKey1)
).execute(client)
).getReceipt(client);

let info = await new ScheduleInfoQuery()
.setScheduleId(scheduleId)
.execute(client);
let executedAt = info.executed ? info.executed : "none";
console.log(
"Scheduled transaction is not yet executed. Executed at: ",
executedAt,
);

// Step 5: Sign the transaction with the other key
let accountBalance = await new AccountBalanceQuery()
.setAccountId(aliceId)
.execute(client);
console.log(
"Alice's account balance before schedule transfer: ",
accountBalance.hbars.toString(),
);

console.log("Signing the new scheduled transaction with the 2nd key");
await (
await (
await new ScheduleSignTransaction()
.setScheduleId(scheduleId)
.freezeWith(client)
.sign(privateKey2)
).execute(client)
).getReceipt(client);

accountBalance = await new AccountBalanceQuery()
.setAccountId(aliceId)
.execute(client);
console.log(
"Alice's account balance after schedule transfer: ",
accountBalance.hbars.toString(),
);

info = await new ScheduleInfoQuery()
.setScheduleId(scheduleId)
.execute(client);
console.log(
"Scheduled transaction is executed. Executed at: ",
info.executed.toDate(),
);

// Step 6: Schedule another transfer transaction
console.log("Creating new scheduled transaction with 10 seconds expiry");
const transfer2 = new TransferTransaction()
.addHbarTransfer(aliceId, new Hbar(-1))
.addHbarTransfer(client.operatorAccountId, new Hbar(1));

const scheduleId2 = (
await (
await transfer2
.schedule()
.setWaitForExpiry(true)
.setExpirationTime(
Timestamp.generate(hasJitter).plusNanos(10 * 1_000_000_000),
) // 10 seconds in milliseconds
.execute(client)
).getReceipt(client)
).scheduleId;

// Step 7: Sign the transaction with one key
console.log("Signing the new scheduled transaction with 1 key");
await (
await (
await new ScheduleSignTransaction()
.setScheduleId(scheduleId2)
.freezeWith(client)
.sign(privateKey1)
).execute(client)
).getReceipt(client);

info = await new ScheduleInfoQuery()
.setScheduleId(scheduleId2)
.execute(client);
executedAt = info.executed ? info.executed : "none";
console.log(
"Scheduled transaction is not yet executed. Executed at: ",
executedAt,
);

// Step 8: Update the account’s key
console.log("Updating Alice's key to be the 1st key");
await (
await (
await (
await new AccountUpdateTransaction()
.setAccountId(aliceId)
.setKey(privateKey1.publicKey)
.freezeWith(client)
.sign(privateKey1)
).sign(privateKey2)
).execute(client)
).getReceipt(client);

// Step 9: Verify that the transfer successfully executes
accountBalance = await new AccountBalanceQuery()
.setAccountId(aliceId)
.execute(client);
console.log(
"Alice's account balance before schedule transfer: ",
accountBalance.hbars.toString(),
);

// Wait for the scheduled transaction to execute
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait for 10 seconds

accountBalance = await new AccountBalanceQuery()
.setAccountId(aliceId)
.execute(client);
console.log(
"Alice's account balance after schedule transfer: ",
accountBalance.hbars.toString(),
);

console.log("Long Term Scheduled Transaction Example Complete!");
}

main().catch(console.error);
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/sdk",
"version": "2.55.0-beta.1",
"version": "2.55.1",
"description": "Hedera™ Hashgraph SDK",
"types": "./lib/index.d.ts",
"main": "./lib/index.cjs",
Expand Down Expand Up @@ -58,13 +58,13 @@
"@ethersproject/rlp": "^5.7.0",
"@grpc/grpc-js": "1.8.2",
"@hashgraph/cryptography": "1.4.8-beta.10",
"@hashgraph/proto": "2.16.0-beta.1",
"@hashgraph/proto": "2.16.0-beta.3",
"axios": "^1.6.4",
"bignumber.js": "^9.1.1",
"bn.js": "^5.1.1",
"crypto-js": "^4.2.0",
"js-base64": "^3.7.4",
"long": "^4.0.0",
"long": "^5.2.3",
"pino": "^8.14.1",
"pino-pretty": "^10.0.0",
"protobufjs": "7.2.5",
Expand All @@ -85,7 +85,6 @@
"@playwright/test": "^1.30.0",
"@types/chai": "^4.3.4",
"@types/crypto-js": "^4.2.0",
"@types/long": "^4.0.2",
"@types/mocha": "^10.0.1",
"@types/node": "^20.8.10",
"@types/utf8": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/proto/.babelrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": ["minify"],
// "presets": ["minify"],
"plugins": [
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-syntax-dynamic-import",
Expand Down
6 changes: 3 additions & 3 deletions packages/proto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hashgraph/proto",
"version": "2.16.0-beta.1",
"version": "2.16.0-beta.3",
"description": "Protobufs for the Hedera™ Hashgraph SDK",
"main": "lib/index.js",
"browser": "src/index.js",
Expand Down Expand Up @@ -34,19 +34,19 @@
"last 1 Firefox versions"
],
"dependencies": {
"long": "^4.0.0",
"long": "^5.2.3",
"protobufjs": "7.2.5"
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
"@types/long": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-preset-minify": "^0.5.2",
"@babel/plugin-transform-runtime": "^7.25.9",
"chalk": "^5.2.0",
"copyfiles": "^2.4.1",
"escodegen": "^2.0.0",
Expand Down
Loading

0 comments on commit 190b836

Please sign in to comment.