Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 20, 2023
2 parents 16be869 + 9145983 commit 25735c2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
- `Contract.getFootprint()` now only returns a single result: the ledger key of the deployed instance for the given ID, because the key for the code entry was incorrect (it should not be the ID but rather the WASM hash, which is not calculatable w/o network access) ([#709](https://github.com/stellar/js-stellar-base/pull/709)).


## [`v10.0.0-beta.4`](https://github.com/stellar/js-stellar-base/compare/v10.0.0-beta.3...v10.0.0-beta.4)

### Fixed
- You can now correctly clone transactions (`TransactionBuilder.cloneFrom`) with large sequence numbers ([#711](https://github.com/stellar/js-stellar-base/pull/711)).


## [`v10.0.0-beta.3`](https://github.com/stellar/js-stellar-base/compare/v10.0.0-beta.2...v10.0.0-beta.3)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-base",
"version": "10.0.0-beta.3",
"version": "10.0.0-beta.4",
"description": "Low-level support library for the Stellar network.",
"main": "./lib/index.js",
"browser": {
Expand Down
43 changes: 26 additions & 17 deletions src/soroban.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
/**

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (16)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (16)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (18)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (18)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (20)

JSDoc syntax error

Check warning on line 1 in src/soroban.js

View workflow job for this annotation

GitHub Actions / build (20)

JSDoc syntax error
* Soroban helper class
* formatting, parsing, and etc
* @class Soroban
* Soroban helper class to assist with formatting and parsing token amounts.
*/
export class Soroban {
/**
* All arithmetic inside the contract is performed on integers to
* avoid potential precision and consistency issues of floating-point
* Given a whole number smart contract amount of a token and an amount of
* decimal places (if the token has any), it returns a "display" value.
*
* This function takes the smart contract value and its decimals (if the token has any) and returns a display value
* @param {string} amount - the token amount you want to display
* @param {number} decimals - specify how many decimal places a token has
* @returns {string} - display value
* All arithmetic inside the contract is performed on integers to avoid
* potential precision and consistency issues of floating-point.
*
* @param {string} amount the token amount you want to display
* @param {number} decimals specify how many decimal places a token has
*
* @returns {string} the display value
* @throws {TypeError} if the given amount has a decimal point already
* @example
* formatTokenAmount("123000", 4) === "12.3";
*/
static formatTokenAmount(amount, decimals) {
let formatted = amount;

if (amount.includes('.')) {
throw new Error('No decimal is allowed');
throw new TypeError('No decimals are allowed');
}

let formatted = amount;
if (decimals > 0) {
if (decimals > formatted.length) {
formatted = ['0', formatted.toString().padStart(decimals, '0')].join(
Expand All @@ -38,19 +42,24 @@ export class Soroban {
}

/**
* parse token amount to use it on smart contract
* Parse a token amount to use it on smart contract
*
* This function takes the display value and its decimals (if the token has
* any) and returns a string that'll be used within the smart contract.
* @param {string} value - the token amount you want to use it on smart contract
* @param {number} decimals - specify how many decimal places a token has
* @returns {string} - smart contract value
*
* @param {string} value the token amount you want to use it on smart
* contract which you've been displaying in a UI
* @param {number} decimals the number of decimal places expected in the
* display value (different than the "actual" number, because suffix zeroes
* might not be present)
*
* @returns {string} the whole number token amount represented by the display
* value with the decimal places shifted over
*
* @example
* const displayValueAmount = "123.4560"
* const parsedAmountForSmartContract = parseTokenAmount("123.4560", 5);
* parsedAmountForSmartContract === "12345600"
* const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5);
* parsedAmtForSmartContract === "12345600"
*/
static parseTokenAmount(value, decimals) {
const [whole, fraction, ...rest] = value.split('.').slice();
Expand Down
2 changes: 1 addition & 1 deletion src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class TransactionBuilder {
throw new TypeError(`expected a 'Transaction', got: ${tx}`);
}

const sequenceNum = `${parseInt(tx.sequence, 10) - 1}`;
const sequenceNum = (BigInt(tx.sequence) - 1n).toString();

let source;
// rebuild the source account based on the strkey
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,5 +1266,5 @@ export function walkInvocationTree(

export namespace Soroban {
function formatTokenAmount(address: string, decimals: number): string;
function parseTokenAmount(value: string, decimals: number): Address;
function parseTokenAmount(value: string, decimals: number): string;
}
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,7 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9:
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==

bn.js@^5.0.0, bn.js@^5.1.1:
bn.js@^5.0.0, bn.js@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==
Expand Down Expand Up @@ -2239,7 +2239,7 @@ browserify-des@^1.0.0:
inherits "^2.0.1"
safe-buffer "^5.1.2"

browserify-rsa@^4.0.0, browserify-rsa@^4.0.1:
browserify-rsa@^4.0.0, browserify-rsa@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.1.0.tgz#b2fd06b5b75ae297f7ce2dc651f918f5be158c8d"
integrity sha512-AdEER0Hkspgno2aR97SAf6vi0y0k8NuOpGnVH3O99rcA5Q6sh8QxcngtHuJ6uXwnfAXNM4Gn1Gb7/MV1+Ymbog==
Expand All @@ -2248,19 +2248,19 @@ browserify-rsa@^4.0.0, browserify-rsa@^4.0.1:
randombytes "^2.0.1"

browserify-sign@^4.0.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.2.1.tgz#eaf4add46dd54be3bb3b36c0cf15abbeba7956c3"
integrity sha512-/vrA5fguVAKKAVTNJjgSm1tRQDHUU6DbwO9IROu/0WAzC8PKhucDSh18J0RMvVeHAn5puMd+QHC2erPRNf8lmg==
version "4.2.2"
resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.2.2.tgz#e78d4b69816d6e3dd1c747e64e9947f9ad79bc7e"
integrity sha512-1rudGyeYY42Dk6texmv7c4VcQ0EsvVbLwZkA+AQB7SxvXxmcD93jcHie8bzecJ+ChDlmAm2Qyu0+Ccg5uhZXCg==
dependencies:
bn.js "^5.1.1"
browserify-rsa "^4.0.1"
bn.js "^5.2.1"
browserify-rsa "^4.1.0"
create-hash "^1.2.0"
create-hmac "^1.1.7"
elliptic "^6.5.3"
elliptic "^6.5.4"
inherits "^2.0.4"
parse-asn1 "^5.1.5"
readable-stream "^3.6.0"
safe-buffer "^5.2.0"
parse-asn1 "^5.1.6"
readable-stream "^3.6.2"
safe-buffer "^5.2.1"

browserify-zlib@^0.2.0:
version "0.2.0"
Expand Down Expand Up @@ -3015,7 +3015,7 @@ electron-to-chromium@^1.4.535:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.546.tgz#673ff64862859b1593cebfbacc5fb6aebef7c457"
integrity sha512-cz9bBM26ZqoEmGHkdHXU3LP7OofVyEzRoMqfALQ9Au9WlB4rogAHzqj/NkNvw2JJjy4xuxS1me+pP2lbCD5Mfw==

elliptic@^6.5.3:
elliptic@^6.5.3, elliptic@^6.5.4:
version "6.5.4"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
Expand Down Expand Up @@ -5607,7 +5607,7 @@ parent-module@^1.0.0:
dependencies:
callsites "^3.0.0"

parse-asn1@^5.0.0, parse-asn1@^5.1.5:
parse-asn1@^5.0.0, parse-asn1@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.6.tgz#385080a3ec13cb62a62d39409cb3e88844cdaed4"
integrity sha512-RnZRo1EPU6JBnra2vGHj0yhp6ebyjBZpmUCLHWiFhxlzvBCCpAuZ7elsBp1PVAbQN0/04VD/19rfzlBSwLstMw==
Expand Down Expand Up @@ -5885,7 +5885,7 @@ readable-stream@^2.0.6:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

readable-stream@^3.0.2, readable-stream@^3.1.1, readable-stream@^3.4.0, readable-stream@^3.5.0, readable-stream@^3.6.0:
readable-stream@^3.0.2, readable-stream@^3.1.1, readable-stream@^3.4.0, readable-stream@^3.5.0, readable-stream@^3.6.0, readable-stream@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967"
integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==
Expand Down

0 comments on commit 25735c2

Please sign in to comment.