forked from svanas/delphereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb3.eth.infura.pas
72 lines (61 loc) · 2.75 KB
/
web3.eth.infura.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{******************************************************************************}
{ }
{ Delphereum }
{ }
{ Copyright(c) 2020 Stefan van As <[email protected]> }
{ Github Repository <https://github.com/svanas/delphereum> }
{ }
{ Distributed under Creative Commons NonCommercial (aka CC BY-NC) license. }
{ }
{******************************************************************************}
unit web3.eth.infura;
{$I web3.inc}
interface
uses
// web3
web3;
type
EInfura = class(EWeb3);
function endpoint(chain: TChain; const projectId: string): string; overload;
function endpoint(chain: TChain; protocol: TProtocol; const projectId: string): string; overload;
implementation
uses
// Delphi
System.SysUtils,
System.TypInfo,
// web3
web3.eth.binance;
function endpoint(chain: TChain; const projectId: string): string;
begin
Result := endpoint(chain, HTTPS, projectId);
end;
function endpoint(chain: TChain; protocol: TProtocol; const projectId: string): string;
const
ENDPOINT: array[TChain] of array[TProtocol] of string = (
('https://mainnet.infura.io/v3/%s', 'wss://mainnet.infura.io/ws/v3/%s'), // Mainnet
('https://ropsten.infura.io/v3/%s', 'wss://ropsten.infura.io/ws/v3/%s'), // Ropsten
('https://rinkeby.infura.io/v3/%s', 'wss://rinkeby.infura.io/ws/v3/%s'), // Rinkeby
('https://goerli.infura.io/v3/%s', 'wss://goerli.infura.io/ws/v3/%s'), // Goerli
('', ''), // Optimism
('', ''), // RSK_main_net
('', ''), // RSK_test_net
('https://kovan.infura.io/v3/%s', 'wss://kovan.infura.io/ws/v3/%s'), // Kovan
('', ''), // BSC_main_net
('', ''), // BSC_test_net
('', '') // xDai
);
begin
Result := ENDPOINT[chain][protocol];
if Result <> '' then
begin
Result := Format(Result, [projectId]);
EXIT;
end;
if chain in [BSC_main_net, BSC_test_net] then
begin
Result := web3.eth.binance.endpoint(chain);
EXIT;
end;
raise EInfura.CreateFmt('%s not supported', [GetEnumName(TypeInfo(TChain), Ord(chain))]);
end;
end.