Skip to content

Commit

Permalink
feat: audit api
Browse files Browse the repository at this point in the history
  • Loading branch information
EthnTuttle committed Aug 31, 2023
1 parent dca2a26 commit 954a0fa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
7 changes: 7 additions & 0 deletions apps/guardian-ui/src/GuardianApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JsonRpcError, JsonRpcWebsocket } from 'jsonrpc-client-websocket';
import { ConfigGenParams, ConsensusState, PeerHashMap } from './setup/types';
import {
AuditSummary,
ConfigResponse,
FederationStatus,
ServerStatus,
Expand Down Expand Up @@ -208,6 +209,7 @@ enum AdminRpc {
inviteCode = 'invite_code',
config = 'config',
module = 'module',
audit = 'audit',
}

export enum LightningModuleRpc {
Expand All @@ -221,6 +223,7 @@ export interface AdminApiInterface extends SharedApiInterface {
fetchEpochCount: () => Promise<number>;
inviteCode: () => Promise<string>;
config: (connection: string) => Promise<ConfigResponse>;
audit: () => Promise<AuditSummary>;
moduleApiCall: <T>(moduleId: number, rpc: ModuleRpc) => Promise<T>;
}

Expand Down Expand Up @@ -366,6 +369,10 @@ export class GuardianApi
return this.base.call<ConfigResponse>(AdminRpc.config, connection);
};

audit = (): Promise<AuditSummary> => {
return this.base.call<AuditSummary>(AdminRpc.audit);
};

moduleApiCall = <T>(moduleId: number, rpc: ModuleRpc): Promise<T> => {
const method = `${AdminRpc.module}_${moduleId}_${rpc}`;
return this.base.call_any_method<T>(method);
Expand Down
7 changes: 5 additions & 2 deletions apps/guardian-ui/src/admin/FederationAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CopyInput } from '@fedimint/ui';
import { useTranslation } from '@fedimint/utils';
import { useAdminContext } from '../hooks';
import {
AuditSummary,
ConfigResponse,
Gateway,
PeerStatus,
Expand All @@ -44,16 +45,18 @@ export const FederationAdmin: React.FC = () => {
const [epochCount, setEpochCount] = useState<number>();
const [status, setStatus] = useState<StatusResponse>();
const [inviteCode, setInviteCode] = useState<string>('');
const [auditSummary, setAuditSummary] = useState<AuditSummary>();
const [config, setConfig] = useState<ConfigResponse>();
const [gateways, setGateways] = useState<Gateway[]>([]);
const { t } = useTranslation();

useEffect(() => {
api.version().then(setVersions).catch(console.error);
api.fetchEpochCount().then(setEpochCount).catch(console.error);
// TODO: poll server status
// TODO: poll server status and audit
api.status().then(setStatus).catch(console.error);
api.inviteCode().then(setInviteCode).catch(console.error);
api.audit().then(setAuditSummary).catch(console.error);
}, [api]);

useEffect(() => {
Expand Down Expand Up @@ -169,7 +172,7 @@ export const FederationAdmin: React.FC = () => {
</Box>
</Box>
</Flex>
<AdminMain />
<AdminMain auditSummary={auditSummary} />
<Flex gap={4}>
<Card flex='1'>
<CardHeader>{t('federation-dashboard.fed-info.label')}</CardHeader>
Expand Down
20 changes: 10 additions & 10 deletions apps/guardian-ui/src/components/AdminMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { ReactComponent as BitcoinIcon } from '../assets/svgs/bitcoin-white.svg'
import { ReactComponent as EcashIcon } from '../assets/svgs/ecash.svg';
import { ReactComponent as BankNotesIcon } from '../assets/svgs/banknotes.svg';
import { ReactComponent as InfoIcon } from '../assets/svgs/info.svg';
import { AuditSummary } from '../types';

interface FederationBalanceProps {
title: string;
amount: number;
amount: bigint;
icon: React.ReactElement<
React.SVGProps<SVGSVGElement> & {
title?: string | undefined;
Expand Down Expand Up @@ -56,7 +57,7 @@ const FederationBalance: FC<FederationBalanceProps> = ({
{title}
</Text>
<Text fontSize='xl' fontWeight='bold' color={theme.colors.gray[900]}>
{amount}
{amount.toString()}
</Text>
</Flex>
</Flex>
Expand All @@ -69,7 +70,11 @@ const FederationBalance: FC<FederationBalanceProps> = ({
);
};

export const AdminMain = () => {
interface AdminMainProps {
auditSummary?: AuditSummary;
}

export const AdminMain: FC<AdminMainProps> = ({ auditSummary }) => {
const theme = useTheme();

return (
Expand All @@ -92,17 +97,12 @@ export const AdminMain = () => {
>
<FederationBalance
title='Bitcoin'
amount={0}
amount={auditSummary?.net_assets ?? (0 as unknown as bigint)}
icon={<BitcoinIcon color={theme.colors.white} />}
/>
<FederationBalance
title='eCash'
amount={0}
icon={<EcashIcon color={theme.colors.blue[600]} />}
/>
<FederationBalance
title='Local currency (US Dollar)'
amount={0}
amount={0 as unknown as bigint}
icon={<BankNotesIcon color={theme.colors.white} />}
/>
</Flex>
Expand Down
10 changes: 10 additions & 0 deletions apps/guardian-ui/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,13 @@ export interface InitializationState {
needsAuth: boolean;
serverStatus: ServerStatus;
}

export interface ModuleSummary {
net_assets: bigint;
}

export interface AuditSummary {
// 9,007,199,254,740,991 milli sats is the upper limit, or ~9007 bitcoin. Should be good?
net_assets: bigint;
module_summaries: Record<string, ModuleSummary>;
}
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ services:
- '18184:18184'
volumes:
- ./fm_2/data:/data
depends_on:
- bitcoind

# gatewayd_2:
# image: fedimint/gatewayd:master
Expand All @@ -92,6 +94,8 @@ services:
- '18185:18185'
volumes:
- ./fm_3/data:/data
depends_on:
- bitcoind

fedimintd_4:
image: fedimint/fedimintd:v0.1.0-rc3
Expand All @@ -107,6 +111,8 @@ services:
- '18186:18186'
volumes:
- ./fm_4/data:/data
depends_on:
- bitcoind

bitcoind:
image: btcpayserver/bitcoin:24.1
Expand Down

0 comments on commit 954a0fa

Please sign in to comment.