Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries committed May 30, 2024
1 parent 7c6be23 commit 698b45d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions source/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ type GenerateUsernameOptions = {
} & BaseOptions;

type GenerateVoteOptions = {
publicKey?: string;
delegate?: string;
validator?: string;
username?: string;
method?: Methods.Vote;
} & TransferOptions;
} & BaseOptions;

export type {
BaseOptions,
Expand Down
12 changes: 6 additions & 6 deletions source/url-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,21 @@ describe("URLBuilder", ({ assert, it }) => {
);
});

it("should generate a vote url from delegate", () => {
it("should generate a vote url from validator public key", () => {
const builder = new URLBuilder("baseUrl");

assert.is(
builder.generateVote("benchdark"),
"baseUrl?method=vote&delegate=benchdark&coin=ARK&nethash=6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
builder.generateVote("03a461f557c88612328c8e6d69991eaa7916359dfd2c6a65fd988b672a8bb780c4"),
"baseUrl?method=vote&validator=03a461f557c88612328c8e6d69991eaa7916359dfd2c6a65fd988b672a8bb780c4&coin=ARK&nethash=6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
);
});

it("should generate a vote url from delegate public key", function () {
it("should generate a vote url with username", () => {
const builder = new URLBuilder("baseUrl");

assert.is(
builder.generateVote("0296893488d335ff818391da7c450cfeb7821a4eb535b15b95808ea733915fbfb1"),
"baseUrl?method=vote&publicKey=0296893488d335ff818391da7c450cfeb7821a4eb535b15b95808ea733915fbfb1&coin=ARK&nethash=6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
builder.generateVote("03a461f557c88612328c8e6d69991eaa7916359dfd2c6a65fd988b672a8bb780c4", "alfy"),
"baseUrl?method=vote&validator=03a461f557c88612328c8e6d69991eaa7916359dfd2c6a65fd988b672a8bb780c4&username=alfy&coin=ARK&nethash=6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
);
});
});
9 changes: 4 additions & 5 deletions source/url-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@ export class URLBuilder {
});
}

public generateVote(subject: string) {
public generateVote(validatorPublicKey: string, username?: string) {
const options: GenerateVoteOptions = {
method: Methods.Vote,
validator: validatorPublicKey,
};

if (subject.length === 66) {
options.publicKey = subject;
} else {
options.delegate = subject;
if (username !== undefined) {
options.username = username;
}

return this.#generate(options);
Expand Down

0 comments on commit 698b45d

Please sign in to comment.