Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/core/src/versionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const version = '2.2.61';
const version = '2.2.62';
const versionBuild = '2020-0101-1';

export default {
Expand Down
34 changes: 32 additions & 2 deletions packages/example/components/chains/btc/example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ export default function BTCExample() {
}}
/>

<ApiPayload
title="disconnect"
description="断开连接"
disableRequestContent
onExecute={async () => {
await provider?.disconnect();
return 'disconnected';
}}
/>

<ApiPayload
title="getAccounts"
description="获取当前账户地址"
Expand Down Expand Up @@ -148,6 +158,26 @@ export default function BTCExample() {
return JSON.stringify(res);
}}
/>
<ApiPayload
title="getBalanceV2"
description="获取当前账户余额 (available/unavailable/total)"
disableRequestContent
onExecute={async () => {
const res = await provider?.getBalanceV2();
return JSON.stringify(res);
}}
/>
<ApiPayload
title="getBitcoinUtxos"
description="获取当前账户 Bitcoin UTXOs"
presupposeParams={params.getBitcoinUtxos}
onExecute={async (request: string) => {
const obj = JSON.parse(request) as { cursor?: number; size?: number };
const res = await provider?.getBitcoinUtxos(obj.cursor, obj.size);
return JSON.stringify(res);
}}
/>

<ApiPayload
title="getNetwork"
description="获取当前网络"
Expand Down Expand Up @@ -219,8 +249,8 @@ export default function BTCExample() {
description="发送交易"
presupposeParams={params.sendBitcoin(account?.address ?? '')}
onExecute={async (request: string) => {
const obj = JSON.parse(request) as { toAddress: string; satoshis: number };
const res = await provider?.sendBitcoin(obj.toAddress, obj.satoshis);
const obj = JSON.parse(request) as { toAddress: string; satoshis: number; options?: { feeRate?: number; memo?: string; memos?: string[] } };
const res = await provider?.sendBitcoin(obj.toAddress, obj.satoshis, obj.options);
return JSON.stringify(res);
}}
/>
Expand Down
26 changes: 26 additions & 0 deletions packages/example/components/chains/btc/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ export default {
value: 'FRACTAL_BITCOIN_TESTNET',
},
],
getBitcoinUtxos: [
{
id: 'getBitcoinUtxos-no-params',
name: 'getBitcoinUtxos (no params)',
value: JSON.stringify({}),
},
{
id: 'getBitcoinUtxos',
name: 'getBitcoinUtxos (first 20)',
value: JSON.stringify({
cursor: 0,
size: 20,
}),
},
],
signMessage: [
{
id: 'signMessage ecdsa default',
Expand Down Expand Up @@ -77,6 +92,17 @@ export default {
satoshis: 1000,
}),
},
{
id: 'sendBitcoin-with-memo',
name: 'SendBitcoin with memo',
value: JSON.stringify({
toAddress: address,
satoshis: 1000,
options: {
memo: 'Hello OneKey',
},
}),
},
],
pushTx: [
{
Expand Down
11 changes: 10 additions & 1 deletion packages/example/components/chains/btc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface IProviderApi {
on(event: string, listener: (...args: any[]) => void): this;
removeListener(event: string, listener: (...args: any[]) => void): this;
requestAccounts(): Promise<string[]>;
disconnect(): Promise<void>;
getAccounts(): Promise<string[]>;
getNetwork(): Promise<string>;
switchNetwork(network: string): Promise<string>;
Expand All @@ -14,12 +15,20 @@ export interface IProviderApi {
unconfirmed: number;
total: number;
}>;
getBalanceV2(): Promise<{
available: number;
unavailable: number;
total: number;
}>;
getBitcoinUtxos(cursor?: number, size?: number): Promise<{ txid: string; vout: number }[]>;
signMessage(msg: string, type: string): Promise<string>;
sendBitcoin(
toAddress: string,
satoshis: number,
options?: {
feeRate: number;
feeRate?: number;
memo?: string;
memos?: string[];
},
): Promise<string>;
pushTx(options: { rawtx: string }): Promise<string>;
Expand Down
34 changes: 33 additions & 1 deletion packages/providers/onekey-btc-provider/src/ProviderBtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
ProviderEventsMap,
MessageType,
BalanceInfo,
BalanceInfoV2,
BitcoinUtxo,
InscriptionInfo,
Chain,
} from './types';
Expand Down Expand Up @@ -171,6 +173,12 @@ class ProviderBtc extends ProviderBtcBase implements IProviderBtc {
});
}

async disconnect() {
return this._request<void>({
method: ProviderMethods.DISCONNECT,
});
}

async getAccounts() {
return this._request<string[]>({
method: ProviderMethods.GET_ACCOUNTS,
Expand Down Expand Up @@ -221,6 +229,22 @@ class ProviderBtc extends ProviderBtcBase implements IProviderBtc {
});
}

async getBalanceV2() {
return this._request<BalanceInfoV2>({
method: ProviderMethods.GET_BALANCE_V2,
});
}

async getBitcoinUtxos(cursor: number | undefined, size: number | undefined) {
return this._request<BitcoinUtxo[]>({
method: ProviderMethods.GET_BITCOIN_UTXOS,
params: {
cursor,
size,
},
});
}

async getInscriptions(cursor = 0, size = 20) {
return this._request<{
total: number;
Expand All @@ -234,13 +258,19 @@ class ProviderBtc extends ProviderBtcBase implements IProviderBtc {
});
}

async sendBitcoin(toAddress: string, satoshis: number, options?: { feeRate: number }) {
async sendBitcoin(
toAddress: string,
satoshis: number,
options?: { feeRate?: number; memo?: string; memos?: string[] },
) {
return this._request<string>({
method: ProviderMethods.SEND_BITCOIN,
params: {
toAddress,
satoshis,
feeRate: options?.feeRate,
memo: options?.memo,
memos: options?.memos,
},
});
}
Expand Down Expand Up @@ -344,5 +374,7 @@ export {
ProviderEventsMap,
MessageType,
BalanceInfo,
BalanceInfoV2,
BitcoinUtxo,
InscriptionInfo,
};
12 changes: 10 additions & 2 deletions packages/providers/onekey-btc-provider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ProviderBtcBase } from './ProviderBtcBase';
export type MessageType = 'ecdsa' | 'bip322-simple';
export type NetworkType = 'livenet' | 'testnet';
export type BalanceInfo = { 'confirmed': number; 'unconfirmed': number; 'total': number };
export type BalanceInfoV2 = { 'available': number; 'unavailable': number; 'total': number };
export type BitcoinUtxo = { 'txid': string; 'vout': number };
export type InscriptionInfo = {
inscriptionId: string;
inscriptionNumber: number;
Expand Down Expand Up @@ -37,7 +39,7 @@ export enum ProviderEvents {
CLOSE = 'close',
ACCOUNTS_CHANGED = 'accountsChanged',
ACCOUNT_CHANGED = 'accountChanged',
NETWORK_CHANGED = 'networkChanged',
NETWORK_CHANGED = 'chainChanged',
MESSAGE_LOW_LEVEL = 'message_low_level',
}

Expand All @@ -59,6 +61,9 @@ export enum ProviderMethods {
SIGN_PSBTS = 'signPsbts',
PUSH_PSBT = 'pushPsbt',
GET_PROVIDER_STATE = 'getProviderState',
DISCONNECT = 'disconnect',
GET_BALANCE_V2 = 'getBalanceV2',
GET_BITCOIN_UTXOS = 'getBitcoinUtxos',
INSCRIBE_TRANSFER = 'inscribeTransfer',

/**
Expand Down Expand Up @@ -123,21 +128,24 @@ export interface IProviderBtc extends ProviderBtcBase {
readonly isOneKey: boolean;

requestAccounts(): Promise<string[]>;
disconnect(): Promise<void>;
getAccounts(): Promise<string[]>;
getNetwork(): Promise<string>;
switchNetwork(network: NetworkType): Promise<void>;
getChain(): Promise<Chain>;
switchChain(chain: string): Promise<Chain>;
getPublicKey(): Promise<string>;
getBalance(): Promise<BalanceInfo | number>;
getBalanceV2(): Promise<BalanceInfoV2>;
getBitcoinUtxos(cursor?: number, size?: number): Promise<BitcoinUtxo[]>;
getInscriptions(
cursor?: number,
size?: number,
): Promise<{
total: number;
list: InscriptionInfo[];
}>;
sendBitcoin(toAddress: string, satoshis: number, options?: { feeRate: number }): Promise<string>;
sendBitcoin(toAddress: string, satoshis: number, options?: { feeRate?: number; memo?: string; memos?: string[] }): Promise<string>;
sendInscription(
toAddress: string,
inscriptionId: string,
Expand Down
Loading