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
9 changes: 6 additions & 3 deletions examples/multisig/basic.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ await multisig
.signed(signature({ sender: alexa }))
.sent()
.dbgStatus("Existential deposit:")
.finalized()
.finalizedEvents()
.unhandleFailed()
.run()

/// Describe the call we wish to dispatch from the multisig.
Expand All @@ -50,7 +51,8 @@ await multisig
.signed(signature({ sender: alexa }))
.sent()
.dbgStatus("Proposal:")
.finalized()
.finalizedEvents()
.unhandleFailed()
.run()

/// Check whether the call has been proposed.
Expand All @@ -73,7 +75,8 @@ await multisig
.signed(signature({ sender: billy }))
.sent()
.dbgStatus("Final approval:")
.finalized()
.finalizedEvents()
.unhandleFailed()
.run()

/// Check to see whether David's balance has in fact changed
Expand Down
5 changes: 4 additions & 1 deletion patterns/multisig/MultisigRune.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MultiAddress } from "@capi/polkadot"
import * as bytes from "../../deps/std/bytes.ts"
import { $, Chain, ChainRune, PatternRune, Rune, RunicArgs, ValueRune } from "../../mod.ts"
import * as util from "../../util/mod.ts"
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved
import { multisigAccountId } from "./multisigAccountId.ts"

export interface Multisig {
Expand All @@ -27,7 +28,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) => !bytes.equals(value, sender.value!))
.sort(util.bytes.compare)
)
}

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 { compare } from "./bytes.ts"

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

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

Deno.test("greater than", () => {
assertEquals(compare(Uint8Array.of(1, 1), Uint8Array.of(1, 0)), 1)
assertEquals(compare(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 compare(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 * as bytes from "./bytes.ts"
export * from "./clock.ts"
export * from "./compression.ts"
export * from "./error.ts"
Expand Down