Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added EventHandle and changed parsing of the AccountState blob #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions lib/wallet/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SHA3 } from 'sha3';
import { CursorBuffer } from '../common/CursorBuffer';
import Addresses from '../constants/Addresses';
import { KeyPair } from '../crypto/Eddsa';
import { EventHandle } from './Events';

export type AccountStates = AccountState[];

Expand All @@ -20,8 +21,8 @@ export class AccountState {
return new AccountState(
new Uint8Array(Buffer.from(address, 'hex')),
new BigNumber(0),
new BigNumber(0),
new BigNumber(0),
EventHandle.default(),
EventHandle.default(),
new BigNumber(0),
true
);
Expand All @@ -35,31 +36,41 @@ export class AccountState {
const balance = cursor.read64();
const delegatedWithdrawalCapability = cursor.readBool();
const receivedEventsCount = cursor.read64();
const receivedEventsKeyLen = cursor.read32();
const receivedEventsKey = cursor.readXBytes(receivedEventsKeyLen);
const sentEventsCount = cursor.read64();
const sentEventsKeyLen = cursor.read32();
const sentEventsKey = cursor.readXBytes(sentEventsKeyLen);
const sequenceNumber = cursor.read64();

return new AccountState(authenticationKey, balance, receivedEventsCount, sentEventsCount, sequenceNumber, delegatedWithdrawalCapability);
return new AccountState(
authenticationKey,
balance,
new EventHandle(receivedEventsKey,receivedEventsCount),
new EventHandle(sentEventsKey,sentEventsCount),
sequenceNumber,
delegatedWithdrawalCapability);
}
public readonly authenticationKey: Uint8Array;
public readonly balance: BigNumber;
public readonly receivedEventsCount: BigNumber;
public readonly sentEventsCount: BigNumber;
public readonly receivedEvents: EventHandle;
public readonly sentEvents: EventHandle;
public readonly sequenceNumber: BigNumber;
public readonly delegatedWithdrawalCapability: boolean;

private constructor(
authenticationKey: Uint8Array,
balance: BigNumber,
receivedEventsCount: BigNumber,
sentEventsCount: BigNumber,
receivedEvents: EventHandle,
sentEvents: EventHandle,
sequenceNumber: BigNumber,
delegatedWithdrawalCapability: boolean,
) {
this.balance = balance;
this.sequenceNumber = sequenceNumber;
this.authenticationKey = authenticationKey;
this.sentEventsCount = sentEventsCount;
this.receivedEventsCount = receivedEventsCount;
this.sentEvents = sentEvents;
this.receivedEvents = receivedEvents;
this.delegatedWithdrawalCapability = delegatedWithdrawalCapability;
}
}
Expand Down
21 changes: 21 additions & 0 deletions lib/wallet/Events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import BigNumber from 'bignumber.js';

export class EventHandle {
public readonly key: Uint8Array;
public readonly count: BigNumber;

public constructor(
key: Uint8Array,
count: BigNumber
) {
this.key = key;
this.count = count;
}

public static default(): EventHandle {
return new EventHandle(
new Uint8Array(),
new BigNumber(0));
}

}