Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

fix: add sort to otherSignatories #993

Merged
merged 10 commits into from
May 12, 2023
7 changes: 5 additions & 2 deletions patterns/multisig/MultisigRune.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MultiAddress } from "@capi/polkadot"
import * as bytes from "../../deps/std/bytes.ts"
import { equals } from "../../deps/std/bytes.ts"
import {
$,
Chain,
Expand All @@ -11,6 +11,7 @@ import {
RunicArgs,
ValueRune,
} from "../../mod.ts"
import { compareBytes } from "../../util/mod.ts"
import { multisigAccountId } from "./multisigAccountId.ts"

export interface Multisig {
Expand Down Expand Up @@ -44,7 +45,9 @@ export class MultisigRune<out C extends Chain, out U> extends PatternRune<Multis
return Rune
.tuple([this.into(ValueRune).access("signatories"), sender])
.map(([signatories, sender]) =>
signatories.filter((value) => !bytes.equals(value, sender.value!))
signatories
.filter((value) => !equals(value, sender.value!))
.sort(compareBytes)
)
}

Expand Down
16 changes: 16 additions & 0 deletions util/bytes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { assertEquals } from "../deps/std/testing/asserts.ts"
import { compareBytes } from "./bytes.ts"

Deno.test("equals", () => {
assertEquals(compareBytes(Uint8Array.of(1), Uint8Array.of(1)), 0)
})

Deno.test("less than", () => {
assertEquals(compareBytes(Uint8Array.of(1, 0), Uint8Array.of(1, 1)), -1)
assertEquals(compareBytes(Uint8Array.of(1, 0), Uint8Array.of(1, 1, 1, 1)), -1)
})

Deno.test("greater than", () => {
assertEquals(compareBytes(Uint8Array.of(1, 1), Uint8Array.of(1, 0)), 1)
assertEquals(compareBytes(Uint8Array.of(1, 1, 1, 1), Uint8Array.of(1, 0)), 1)
})
13 changes: 13 additions & 0 deletions util/bytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function compareBytes(a: Uint8Array, b: Uint8Array): number {
for (let i = 0; i < a.byteLength; i++) {
if (a[i]! < b[i]!) {
return -1
}

if (a[i]! > b[i]!) {
return 1
}
}

return a.byteLength > b.byteLength ? 1 : a.byteLength < b.byteLength ? -1 : 0
}
1 change: 1 addition & 0 deletions util/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// moderate --exclude cache port.ts proxyWebSocket.ts tsFormatter.ts

export * from "./ArrayOfLength.ts"
export * from "./bytes.ts"
export * from "./clock.ts"
export * from "./compression.ts"
export * from "./error.ts"
Expand Down