Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdtzmn committed Mar 19, 2021
1 parent 5885475 commit b02ff54
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/typescript_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function main() {
});

const signedTxn = txn.signTxn(sk);
console.log(algosdk.decodeObj(signedTxn));
console.log(algosdk.decodeSignedTransaction(signedTxn));
}

main().catch(console.error);
14 changes: 5 additions & 9 deletions src/encoding/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import base32 from 'hi-base32';
import * as nacl from '../nacl/naclWrappers';
import * as utils from '../utils/utils';
import { Address } from '../types/address';
import { MultisigMetadata } from '../types/multisig';

const ALGORAND_ADDRESS_BYTE_LENGTH = 36;
const ALGORAND_CHECKSUM_BYTE_LENGTH = 4;
Expand Down Expand Up @@ -39,11 +40,8 @@ export const UNEXPECTED_PK_LEN_ERROR_MSG =
* @param address an Algorand address with checksum.
* @returns the decoded form of the address's public key and checksum
*/
export function decodeAddress(address: string | String): Address {
if (
!(typeof address === 'string' || address instanceof String) ||
address.length !== ALGORAND_ADDRESS_LENGTH
)
export function decodeAddress(address: string): Address {
if (typeof address !== 'string' || address.length !== ALGORAND_ADDRESS_LENGTH)
throw new Error(MALFORMED_ADDRESS_ERROR_MSG);

// try to decode
Expand Down Expand Up @@ -124,10 +122,8 @@ export function fromMultisigPreImg({
version,
threshold,
pks,
}: {
version: number;
threshold: number;
pks: ArrayLike<ArrayLike<number>>;
}: Omit<MultisigMetadata, 'addrs'> & {
pks: Uint8Array[];
}) {
if (version !== 1 || version > 255 || version < 0) {
// ^ a tad redundant, but in case in the future version != 1, still check for uint8
Expand Down
2 changes: 1 addition & 1 deletion src/encoding/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ERROR_CONTAINS_EMPTY_STRING =
* @param obj
* @returns / {true, empty key} if contains empty, {false, undefined} otherwise
*/
export function containsEmpty(obj: Record<string | number | symbol, any>) {
function containsEmpty(obj: Record<string | number | symbol, any>) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if (!obj[key] || obj[key].length === 0) {
Expand Down
9 changes: 7 additions & 2 deletions src/encoding/uint64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ export function encodeUint64(num: number | bigint) {
* @returns The integer that was encoded in the input data. The return type will
* be determined by the parameter decodingMode.
*/
/* eslint-disable no-unused-vars,no-redeclare */
export function decodeUint64(data: Uint8Array, decodingMode: 'safe'): number;
export function decodeUint64(
data: Uint8Array,
decodingMode: 'safe' | 'mixed' | 'bigint' = 'safe'
) {
decodingMode: 'mixed'
): number | bigint;
export function decodeUint64(data: Uint8Array, decodingMode: 'bigint'): bigint;
export function decodeUint64(data: any, decodingMode: any = 'safe') {
/* eslint-enable no-unused-vars,no-redeclare */
if (
decodingMode !== 'safe' &&
decodingMode !== 'mixed' &&
Expand Down
9 changes: 4 additions & 5 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface TransactionStorageStructure
flatFee: boolean;
reKeyTo?: string | Address;
nonParticipation?: boolean;
group: undefined;
group: Buffer;
}

/**
Expand Down Expand Up @@ -160,11 +160,9 @@ export class Transaction implements TransactionStorageStructure {
nonParticipation?: boolean;
group: undefined;

constructor(transactionObj: AnyTransaction) {
// Create a mutable copy of the transaction object
const transaction: AnyTransaction = { ...transactionObj };

constructor({ ...transaction }: AnyTransaction) {
// Populate defaults
/* eslint-disable no-param-reassign */
const defaults: Partial<TransactionParams> = {
type: TransactionType.pay,
flatFee: false,
Expand All @@ -190,6 +188,7 @@ export class Transaction implements TransactionStorageStructure {
) {
transaction.nonParticipation = defaults.nonParticipation;
}
/* eslint-enable no-param-reassign */

// Move suggested parameters from its object to inline
if (
Expand Down
6 changes: 3 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ interface JSONOptions {

/**
* Parse JSON with additional options.
* @param {string} str The JSON string to parse.
* @param {object} options Parsing options.
* @param {"default" | "safe" | "mixed" | "bigint"} options.intDecoding Configure how integers in
* @param str The JSON string to parse.
* @param options Parsing options.
* @param options.intDecoding Configure how integers in
* this request's JSON response will be decoded.
*
* The options are:
Expand Down

0 comments on commit b02ff54

Please sign in to comment.