Skip to content

Commit

Permalink
Merge pull request #125 from buidler-labs/develop
Browse files Browse the repository at this point in the history
0.8.1
  • Loading branch information
3Nigma committed Nov 24, 2022
2 parents 676b1cf + 7e06cd0 commit df37dea
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 87 deletions.
1 change: 1 addition & 0 deletions .cspell/custom-dictionary-workspace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hashgraph
Hbar
hbars
Hederas
ipfs
localised
polies
previewnet
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
description: "Hedera network to run the tests on"
required: true
type: environment
default: hedera-testnet
default: hedera-devnet

env:
HEDERA_NETWORK: ${{ secrets.HEDERAS_NETWORK }}
Expand Down Expand Up @@ -42,6 +42,7 @@ jobs:
- name: Testing
env:
HEDERAS_NETWORK: ${{ secrets.HEDERAS_NETWORK }}
HEDERAS_NODES: ${{ secrets.HEDERAS_NODES }}
HEDERAS_OPERATOR_ID: ${{ secrets.HEDERAS_OPERATOR_ID }}
HEDERAS_OPERATOR_KEY: ${{ secrets.HEDERAS_OPERATOR_KEY }}
HEDERAS_DEFAULT_CONTRACT_REQUESTS_RETURN_ONLY_RECEIPTS: ${{ secrets.HEDERAS_DEFAULT_CONTRACT_REQUESTS_RETURN_ONLY_RECEIPTS }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
jobs:
main_test:
runs-on: ubuntu-latest
environment: hedera-testnet
environment: hedera-devnet
strategy:
matrix:
npm_test_script: ["test:node", "test:jsdom"]
Expand All @@ -33,6 +33,7 @@ jobs:
env:
NODE_OPTIONS: "--max_old_space_size=4096"
HEDERAS_NETWORK: ${{ secrets.HEDERAS_NETWORK }}
HEDERAS_NODES: ${{ secrets.HEDERAS_NODES }}
HEDERAS_OPERATOR_ID: ${{ secrets.HEDERAS_OPERATOR_ID }}
HEDERAS_OPERATOR_KEY: ${{ secrets.HEDERAS_OPERATOR_KEY }}
HEDERAS_DEFAULT_CONTRACT_REQUESTS_RETURN_ONLY_RECEIPTS: ${{ secrets.HEDERAS_DEFAULT_CONTRACT_REQUESTS_RETURN_ONLY_RECEIPTS }}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"cSpell.customDictionaries": {
"custom-dictionary-workspace": {
"name": "custom-dictionary-workspace",
"path": "${workspaceFolder:hedera-strato-js}/.cspell/custom-dictionary-workspace.txt",
"path": "${workspaceFolder:hashgraph-venin-js}/.cspell/custom-dictionary-workspace.txt",
"addWords": true,
"scope": "workspace"
}
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Hedera Strato JS
# Hedera Venin JS

![NodeJS/JsDOM/Browser tests](https://img.shields.io/github/workflow/status/buidler-labs/hedera-strato-js/test-nodejs-jsdom-browser?style=flat-square&label=tests&color=yellowgreen)
[![codecov](https://img.shields.io/codecov/c/github/buidler-labs/hedera-strato-js?style=flat-square)](https://codecov.io/gh/buidler-labs/hedera-strato-js)
![NodeJS/JsDOM/Browser tests](https://img.shields.io/github/workflow/status/buidler-labs/hashgraph-venin-js/test-nodejs-jsdom-browser?style=flat-square&label=tests&color=yellowgreen)
[![codecov](https://img.shields.io/codecov/c/github/buidler-labs/hashgraph-venin-js?style=flat-square)](https://codecov.io/gh/buidler-labs/hashgraph-venin-js)

[![Discord support channel](https://img.shields.io/discord/949250301792239686?style=flat-square)](https://discord.com/invite/4mYCre869F)
![contributions](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)
![license](https://img.shields.io/github/license/buidler-labs/hedera-strato-js.svg?colorB=ff0000&style=flat-square)
![license](https://img.shields.io/github/license/buidler-labs/hashgraph-venin-js.svg?colorB=ff0000&style=flat-square)

![node version](https://img.shields.io/badge/Node.js-%3E%3D14.8.0-orange.svg?style=flat-square)
![npm version](https://img.shields.io/npm/v/@buidlerlabs/hedera-strato-js.svg?style=flat-square)
![npm version](https://img.shields.io/npm/v/@buidlerlabs/hashgraph-venin-js.svg?style=flat-square)

[![NPM](https://nodei.co/npm/@buidlerlabs/hedera-strato-js.png?mini=true)](https://nodei.co/npm/@buidlerlabs/hedera-strato-js/)
[![NPM](https://nodei.co/npm/@buidlerlabs/hashgraph-venin-js.png?mini=true)](https://nodei.co/npm/@buidlerlabs/hashgraph-venin-js/)

Write Web3 [Hedera](https://hedera.com/) smart-contract dApps frictionless and with ease, without having to deal with the hustle and bustle of [Hedera's verbose, underlying services](https://docs.hedera.com/guides/docs/sdks).

Expand All @@ -22,14 +22,14 @@ Write Web3 [Hedera](https://hedera.com/) smart-contract dApps frictionless and w
## Features

Strato already is packed with a lot of stuff:
Venin already is packed with a lot of stuff:
✔️ Compile a Solidity contract to obtain its Hedera accepted ABI directly from within the library (no external compiler required)
✔️ Deploy a contract to the network
✔️ Use a fluent API to interact with deployed, _live entities_ such as contracts
✔️ Pubsub for contract emitted events
✔️ Pubsub for transaction receipts
✔️ Fine grained cost-control
✔️ Browser bundle-able via a custom made Rollup plugin ([webpack pending](https://github.com/buidler-labs/hedera-strato-js/issues/26))
✔️ Browser bundle-able via a custom made Rollup plugin ([webpack pending](https://github.com/buidler-labs/hashgraph-venin-js/issues/26))
✔️ Using Hedera File Storage as a place to store generic files and JSONs
✔️ Create token via the Hedera Token Service (HTS)
✔️ Create a Hedera account
Expand All @@ -48,7 +48,7 @@ Strato already is packed with a lot of stuff:

## The drive

As any good-striving, long-lasting, endeavour, we are using Strato to hopefully fuel everything that we, here at BuiDler Labs, build on Hedera. Our Hedera portfolio currently consists of:
As any good-striving, long-lasting, endeavour, we are using Venin to hopefully fuel everything that we, here at BuiDler Labs, build on Hedera. Our Hedera portfolio currently consists of:

- [FileCoin-Hedera Grant](https://github.com/taskbar-team/hedera-filecoin-devgrant) - a development grant used to put the foundations of [MyTaskbar](https://mytaskbar.io/) v2, the more decentralized version
- [HeadStarter](headstarter.org) - the first Hedera IDO platform
Expand Down Expand Up @@ -82,7 +82,7 @@ HEDERAS_OPERATOR_KEY=...
pragma solidity ^0.8.3;
contract HelloWorld {
string public greet = "Hello Hedera Strato!";
string public greet = "Hello Hedera Venin!";
}
```

Expand All @@ -98,7 +98,7 @@ const liveContract = await session.upload(helloWorldContract);
console.log(await liveContract.greet());
```

If all goes well, you should see the expected `Hello Hedera Strato!` logged inside your console signifying that the contract was successfully compiled, uploaded and executed.
If all goes well, you should see the expected `Hello Hedera Venin!` logged inside your console signifying that the contract was successfully compiled, uploaded and executed.

Also, if you want a quick play-through a similar example, please have a look at [our minimum-working code](https://github.com/buidler-labs/hsj-example) repo.

Expand All @@ -114,7 +114,7 @@ $ npm test
## Contributions

Do you think we missed anything? Want some feature badly? Do you have an idea of something that we might improve? Head over to [our issues page](https://github.com/buidler-labs/hedera-strato-js/issues) and let us know! We want Strato to be a community-lead initiative. This means that any opinion or critic is encouraged (and even welcomed)!
Do you think we missed anything? Want some feature badly? Do you have an idea of something that we might improve? Head over to [our issues page](https://github.com/buidler-labs/hashgraph-venin-js/issues) and let us know! We want Venin to be a community-lead initiative. This means that any opinion or critic is encouraged (and even welcomed)!

Of course, if you're eager to write it yourself, that's also fine and dandy! Just fork us, add your changes and open a pull request. We'll take it from there ...

Expand Down
2 changes: 1 addition & 1 deletion jest.common.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = {
collectCoverage: true,
coveragePathIgnorePatterns: ["test/*", "lib.cjs/*", "lib.esm/*"],
displayName: "hedera-strato",
displayName: "hashgraph-venin",
moduleFileExtensions: ["js", "ts"],
preset: "ts-jest",
setupFiles: ["dotenv/config"],
Expand Down
1 change: 1 addition & 0 deletions lib/ApiSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export type SessionDefaults = {
emitLiveContractReceipts: boolean;
onlyReceiptsFromContractRequests: boolean;
paymentForContractQuery: number;
tokenCreateTransactionFee: number;
};

const SESSION_CONSTRUCTOR_GUARD = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/ContractRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ContractRegistry {
) {
// No-op
console.error(
"ContractRegistry could not load a Contract due to library linking not currently being supported. This will be supported once https://github.com/buidler-labs/hedera-strato-js/issues/38 is resolved."
"ContractRegistry could not load a Contract due to library linking not currently being supported. This will be supported once https://github.com/buidler-labs/hashgraph-venin-js/issues/38 is resolved."
);
} else {
// no mercy
Expand Down
2 changes: 1 addition & 1 deletion lib/HederaNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type NetworkDefaults = {
};

/**
* The main entry-class for the Hedera Strato library.
* The main entry-class for the Hedera Venin library.
*
* It starts out by referencing a Hedera Network (being it [official](https://docs.hedera.com/guides/mirrornet/hedera-mirror-node#mainnet) or {@link HEDERA_CUSTOM_NET_NAME | custom})
* client before allowing to generate an {@link ApiSession} through the {@link HederaNetwork.login} method call.
Expand Down
6 changes: 6 additions & 0 deletions lib/StratoContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ export class StratoContext {
resolveSessionDefaultValueFor("payment_for_contract_query") ??
"20000000"
),
tokenCreateTransactionFee:
rParams.session?.defaults?.tokenCreateTransactionFee ??
parseInt(
resolveSessionDefaultValueFor("token_create_transaction_fee") ??
"5000000000"
),
};
}
}
2 changes: 1 addition & 1 deletion lib/compiler/ContractCompileResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This module is responsible for linking solidity-contract abi code against already deployed libraries
*
* Be very mindful when editing it to not include to many external module dependencies which
* could burden the bundler plugins that reference it (eg. @buidlerlabs/rollup-plugin-hedera-strato).
* could burden the bundler plugins that reference it (eg. @buidlerlabs/rollup-plugin-hashgraph-venin).
*
* Note: This is also exported via package.json but is done so for internal use only and, as such,
* does not guarantee module api stability.
Expand Down
74 changes: 58 additions & 16 deletions lib/compiler/SolidityCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Wrapper around the Solidity solc-js compiler meant for Node runtime consumption
// Browser variants do not use this and instead polyfill it
// Please see the rollup-strato plugin implementation for more info.
// Please see the rollup-venin plugin implementation for more info.
//
// NOTE: We have to keep this module as light as possible (least dependencies as possible) so that
// we can polyfill this easily (eg. strato-rollup-plugin).
// we can polyfill this easily (eg. venin-rollup-plugin).
// This means no @hashgraph/sdk here.
import * as fs from "fs";
import * as sdkPath from "path";
Expand All @@ -25,7 +25,7 @@ export interface CompilationResult {

export const VIRTUAL_SOURCE_CONTRACT_FILE_NAME = "__contract__.sol";

// Fix for https://github.com/buidler-labs/hedera-strato-js/issues/81
// Fix for https://github.com/buidler-labs/hashgraph-venin-js/issues/81
// as initially reported by https://github.com/ethereum/solidity/issues/12228
const listeners = process.listeners("unhandledRejection");
if (undefined !== listeners[listeners.length - 1]) {
Expand All @@ -39,28 +39,29 @@ export class SolidityCompiler {
const basePath = sdkPath.resolve(
process.env.HEDERAS_CONTRACTS_RELATIVE_PATH || "contracts"
);
const absoluteSourcePath =
path && sdkPath.isAbsolute(path)
? path
: sdkPath.join(basePath, path || "");
const content = code
? code
: fs.readFileSync(
sdkPath.isAbsolute(path) ? path : sdkPath.join(basePath, path),
"utf8"
);
? SolidityCompiler.sanitize(code)
: SolidityCompiler.getSource(absoluteSourcePath);
// Note: Further options and info is available
// here https://docs.soliditylang.org/en/v0.8.10/using-the-compiler.html#input-description and
// here https://docs.soliditylang.org/en/v0.8.10/using-the-compiler.html#compiler-input-and-output-json-description
const solInput = {
language: "Solidity",
settings: {
// FIXME: Issue #91: Make SolidityCompiler execution configurable
optimizer: {
enabled: true,
runs: 200,
},
metadata: {
// disabling metadata hash embedding to make the bytecode generation predictable at test-time
// see https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
bytecodeHash: process.env.NODE_ENV === "test" ? "none" : "ipfs",
},
// FIXME: Issue #91: Make SolidityCompiler execution configurable
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
"*": {
"*": ["*"],
Expand All @@ -80,7 +81,7 @@ export class SolidityCompiler {
? process.env.HEDERAS_CONTRACTS_INCLUDED_PREFIXES.split(/\s*,\s*/)
: []),
];
const importsResolver = (sourcePath) => {
const importsResolver = (sourcePath: string) => {
for (const prefix of importPrefixes) {
let resolvedSourcePath;

Expand All @@ -96,10 +97,10 @@ export class SolidityCompiler {
if (fs.existsSync(resolvedSourcePath)) {
try {
return {
contents: fs.readFileSync(resolvedSourcePath).toString("utf8"),
contents: SolidityCompiler.getSource(resolvedSourcePath),
};
} catch (e) {
return { error: "Error reading " + resolvedSourcePath + ": " + e };
return { error: `Error reading '${resolvedSourcePath}: ${e}` };
}
}
}
Expand All @@ -119,4 +120,45 @@ export class SolidityCompiler {
jCompileResult
);
}

/**
* Given the path of a solidity file, reads and returns its source code following any necessary preprocessing.
*
* Note: This provides fix for #114 (https://github.com/buidler-labs/hashgraph-venin-js/issues/114)
* We need to replace all relative imports (. and .. alike) otherwise the VFS could load the same identifier into multiple references which would end up
* erroring out with "Identifier already declared." error messages.
*
* @param fullSolPath - The absolute .sol path to be resolved
* @returns the loaded source content following any preprocessing
*/
private static getSource(fullSolPath: string): string {
const solFolderPath = sdkPath.dirname(fullSolPath);
let fSource = fs.readFileSync(fullSolPath, "utf-8");
const importRegex = /[ ]*import\s*[\\]?['"]([\\.]?\.\/[^\\'"]+)[\\]?['"];/g;
const importMatches = fSource.match(importRegex) || [];

for (const match of importMatches) {
const importedEntity = importRegex.exec(fSource);
const resolvedImportFilePath = sdkPath.join(
solFolderPath,
importedEntity[1]
);

// TODO: log `[${fullSolPath}] Replacing '${importedEntity[1]}' with '${resolvedImportFilePath}'`
fSource = fSource.replace(match, `import '${resolvedImportFilePath}';`);
}
return fSource;
}

private static sanitize(rootCode: string): string {
const dotDotRelativeImportRegex =
/[ ]*import\s*[\\]?['"](\.\.\/[^\\'"]+)[\\]?['"];/g;

if (dotDotRelativeImportRegex.test(rootCode)) {
throw new Error(
"Compiling root-code with double relative import component (..) is not yet supported and will be implemented in #117."
);
}
return rootCode;
}
}
2 changes: 1 addition & 1 deletion lib/errors/CompileIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CompileIssues extends Error {
static _listOfSimpleIssueMessagesFor(rawIssues) {
return rawIssues.map(
(rIssue) =>
`[ ${rIssue.sourceLocation.start}:${rIssue.sourceLocation.end} ] ${rIssue.message}`
`[ ${rIssue.sourceLocation.start}:${rIssue.sourceLocation.end} ] ${rIssue.formattedMessage}`
);
}

Expand Down
16 changes: 16 additions & 0 deletions lib/static/create/Token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AccountId,
Hbar,
TokenType as HederaTokenType,
Key,
Timestamp,
Expand Down Expand Up @@ -35,6 +36,7 @@ export type CreateTokenFeatures = TokenFeatures & {
decimals?: number | Long.Long;
customFees?: { feeCollectorAccountId?: string | AccountId | undefined }[];
freezeDefault?: boolean;
maxTransactionFee?: number | Long.Long | Hbar;
};

type TokenKeys = {
Expand Down Expand Up @@ -162,6 +164,20 @@ export class Token extends BasicCreatableEntity<LiveToken> {
const createTokenTransaction = new TokenCreateTransaction(
constructorArgs as unknown
);

let transactionFee: Hbar;
if(this.info.maxTransactionFee) {
transactionFee = this.info.maxTransactionFee instanceof Hbar
? this.info.maxTransactionFee
: new Hbar(this.info.maxTransactionFee)
} else if (session.defaults.tokenCreateTransactionFee > 0) {
transactionFee = Hbar.fromTinybars(
session.defaults.tokenCreateTransactionFee
);
}
if(transactionFee) {
createTokenTransaction.setMaxTransactionFee(transactionFee);
}
const creationReceipt = await session.execute(
createTokenTransaction,
TypeOfExecutionReturn.Receipt,
Expand Down
Loading

0 comments on commit df37dea

Please sign in to comment.