Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Concordium/concordium-node-sdk-js i…
Browse files Browse the repository at this point in the history
…nto main
  • Loading branch information
orhoj committed Sep 27, 2021
2 parents 68a24a9 + cd28c64 commit 1fc8c4d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 12 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,22 @@ const bestBlock = consensusStatus.bestBlock;
## Check block for transfers with memo
The following example demonstrates how to check and parse a block
for transfers with a memo.
```
```js
const blockHash = "b49bb1c06c697b7d6539c987082c5a0dc6d86d91208874517ab17da752472edf";
const blockSummary = await client.getBlockSummary(blockHash);
const transactionSummaries = blockSummary.transactionSummaries;

for (const transactionSummary of transactionSummaries) {
if (instanceOfTransferWithMemoTransactionSummary(transactionSummary)) {
const [transferredEvent, memoEvent] = transactionSummary.result.events;
if (transactionSummary.result.outcome === 'success') {
if (instanceOfTransferWithMemoTransactionSummary(transactionSummary)) {
const [transferredEvent, memoEvent] = transactionSummary.result.events;

const toAddress = transferredEvent.to.address;
const amount = transferredEvent.amount;
const memo = memoEvent.memo;
const toAddress = transferredEvent.to.address;
const amount = transferredEvent.amount;
const memo = memoEvent.memo;

// Apply business logic to toAddress, amount and memo...
// Apply business logic to toAddress, amount and memo...
}
}
}
```
Expand Down
74 changes: 70 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,70 @@ export interface MemoEvent {
memo: string;
}

export interface EventResult {
outcome: string;
// TODO Resolve the types completely.
/**
* An enum containing all the possible reject reasons that can be
* received from a node as a response to a transaction submission.
*
* This should be kept in sync with the list of reject reasons
* found here: https://github.com/Concordium/concordium-base/blob/main/haskell-src/Concordium/Types/Execution.hs
*/
export enum RejectReasonTag {
ModuleNotWF = 'ModuleNotWF',
ModuleHashAlreadyExists = 'ModuleHashAlreadyExists',
InvalidAccountReference = 'InvalidAccountReference',
InvalidInitMethod = 'InvalidInitMethod',
InvalidReceiveMethod = 'InvalidReceiveMethod',
InvalidModuleReference = 'InvalidModuleReference',
InvalidContractAddress = 'InvalidContractAddress',
RuntimeFailure = 'RuntimeFailure',
AmountTooLarge = 'AmountTooLarge',
SerializationFailure = 'SerializationFailure',
OutOfEnergy = 'OutOfEnergy',
RejectedInit = 'RejectedInit',
RejectedReceive = 'RejectedReceive',
NonExistentRewardAccount = 'NonExistentRewardAccount',
InvalidProof = 'InvalidProof',
AlreadyABaker = 'AlreadyABaker',
NotABaker = 'NotABaker',
InsufficientBalanceForBakerStake = 'InsufficientBalanceForBakerStake',
StakeUnderMinimumThresholdForBaking = 'StakeUnderMinimumThresholdForBaking',
BakerInCooldown = 'BakerInCooldown',
DuplicateAggregationKey = 'DuplicateAggregationKey',
NonExistentCredentialID = 'NonExistentCredentialID',
KeyIndexAlreadyInUse = 'KeyIndexAlreadyInUse',
InvalidAccountThreshold = 'InvalidAccountThreshold',
InvalidCredentialKeySignThreshold = 'InvalidCredentialKeySignThreshold',
InvalidEncryptedAmountTransferProof = 'InvalidEncryptedAmountTransferProof',
InvalidTransferToPublicProof = 'InvalidTransferToPublicProof',
EncryptedAmountSelfTransfer = 'EncryptedAmountSelfTransfer',
InvalidIndexOnEncryptedTransfer = 'InvalidIndexOnEncryptedTransfer',
ZeroScheduledAmount = 'ZeroScheduledAmount',
NonIncreasingSchedule = 'NonIncreasingSchedule',
FirstScheduledReleaseExpired = 'FirstScheduledReleaseExpired',
ScheduledSelfTransfer = 'ScheduledSelfTransfer',
InvalidCredentials = 'InvalidCredentials',
DuplicateCredIDs = 'DuplicateCredIDs',
NonExistentCredIDs = 'NonExistentCredIDs',
RemoveFirstCredential = 'RemoveFirstCredential',
CredentialHolderDidNotSign = 'CredentialHolderDidNotSign',
NotAllowedMultipleCredentials = 'NotAllowedMultipleCredentials',
NotAllowedToReceiveEncrypted = 'NotAllowedToReceiveEncrypted',
NotAllowedToHandleEncrypted = 'NotAllowedToHandleEncrypted',
}

export interface RejectReason {
tag: RejectReasonTag;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contents: any;
}

interface RejectedEventResult {
outcome: 'reject';
rejectReason: RejectReason;
}

interface SuccessfulEventResult {
outcome: 'success';
events: (
| TransactionEvent
| TransferredEvent
Expand All @@ -117,6 +178,11 @@ export interface EventResult {
)[];
}

export type EventResult =
| SuccessfulEventResult
| TransferWithMemoEventResult
| RejectedEventResult;

interface BaseTransactionSummaryType {
type:
| 'accountTransaction'
Expand Down Expand Up @@ -149,7 +215,7 @@ interface GenericTransactionSummary extends BaseTransactionSummary {
}

interface TransferWithMemoEventResult {
outcome: string;
outcome: 'success';
events: [TransferredEvent, MemoEvent];
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function buildJsonResponseReviver<T>(
}
return result;
}
return BigInt(value);
return value === null ? value : BigInt(value);
}
return value;
};
Expand Down

0 comments on commit 1fc8c4d

Please sign in to comment.