Skip to content

Commit

Permalink
v10.5.0: introduce solana platform specific package and start using j…
Browse files Browse the repository at this point in the history
…scc for platfom specific code
  • Loading branch information
10xSebastian committed Mar 14, 2023
1 parent ea6bf28 commit f981a79
Show file tree
Hide file tree
Showing 26 changed files with 1,097 additions and 625 deletions.
102 changes: 69 additions & 33 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ var estimateEVM = ({ provider, from, to, value, method, api, params }) => {
}
};

let supported = ['ethereum', 'bsc', 'polygon', 'fantom', 'velas'];
supported.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'velas'];
supported.solana = [];

const BATCH_INTERVAL = 10;
const CHUNK_SIZE = 99;

Expand Down Expand Up @@ -222,10 +218,24 @@ var EVM = {
setProvider: setProvider$1,
};

let supported = ['ethereum', 'bsc', 'polygon', 'fantom', 'velas'];
supported.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'velas'];
supported.solana = [];

const getProvider = async (blockchain)=>{

if(supported.evm.includes(blockchain)) {


return await EVM.getProvider(blockchain)


} else if(supported.solana.includes(blockchain)) {


return await Solana.getProvider(blockchain)


} else {
throw 'Unknown blockchain: ' + blockchain
}
Expand All @@ -234,7 +244,17 @@ const getProvider = async (blockchain)=>{
const setProvider = (blockchain, provider)=>{

if(supported.evm.includes(blockchain)) {


return EVM.setProvider(blockchain, provider)


} else if(supported.solana.includes(blockchain)) {


return Solana.setProvider(blockchain, provider)


} else {
throw 'Unknown blockchain: ' + blockchain
}
Expand All @@ -243,7 +263,17 @@ const setProvider = (blockchain, provider)=>{
const setProviderEndpoints = (blockchain, endpoints)=>{

if(supported.evm.includes(blockchain)) {


return EVM.setProviderEndpoints(blockchain, endpoints)


} else if(supported.solana.includes(blockchain)) {


return Solana.setProviderEndpoints(blockchain, endpoints)


} else {
throw 'Unknown blockchain: ' + blockchain
}
Expand Down Expand Up @@ -366,33 +396,6 @@ let estimate = async function ({ blockchain, from, to, value, method, api, param
})
};

var parseUrl = (url) => {
if (typeof url == 'object') {
return url
}
let deconstructed = url.match(/(?<blockchain>\w+):\/\/(?<part1>[\w\d]+)(\/(?<part2>[\w\d]+)*)?/);

if(deconstructed.groups.part2 == undefined) {
if(deconstructed.groups.part1.match(/\d/)) {
return {
blockchain: deconstructed.groups.blockchain,
address: deconstructed.groups.part1
}
} else {
return {
blockchain: deconstructed.groups.blockchain,
method: deconstructed.groups.part1
}
}
} else {
return {
blockchain: deconstructed.groups.blockchain,
address: deconstructed.groups.part1,
method: deconstructed.groups.part2
}
}
};

let paramsToContractArgs = ({ contract, method, params }) => {
let fragment = contract.interface.fragments.find((fragment) => {
return fragment.name == method
Expand Down Expand Up @@ -435,6 +438,33 @@ var requestEVM = async ({ blockchain, address, api, method, params, block }) =>
}
};

var parseUrl = (url) => {
if (typeof url == 'object') {
return url
}
let deconstructed = url.match(/(?<blockchain>\w+):\/\/(?<part1>[\w\d]+)(\/(?<part2>[\w\d]+)*)?/);

if(deconstructed.groups.part2 == undefined) {
if(deconstructed.groups.part1.match(/\d/)) {
return {
blockchain: deconstructed.groups.blockchain,
address: deconstructed.groups.part1
}
} else {
return {
blockchain: deconstructed.groups.blockchain,
method: deconstructed.groups.part1
}
}
} else {
return {
blockchain: deconstructed.groups.blockchain,
address: deconstructed.groups.part1,
method: deconstructed.groups.part2
}
}
};

let request = async function (url, options) {
let { blockchain, address, method } = parseUrl(url);
let { api, params, cache: cache$1, block } = (typeof(url) == 'object' ? url : options) || {};
Expand All @@ -444,12 +474,18 @@ let request = async function (url, options) {
key: [blockchain, address, method, params, block],
call: async()=>{
if(supported.evm.includes(blockchain)) {


return requestEVM({ blockchain, address, api, method, params, block })
} else {


} else if(supported.solana.includes(blockchain)) ; else {
throw 'Unknown blockchain: ' + blockchain
}
}
})
};

export { estimate, getProvider, request, resetCache, setProvider, setProviderEndpoints };
const simulate = undefined;

export { estimate, getProvider, request, resetCache, setProvider, setProviderEndpoints, simulate };
Loading

0 comments on commit f981a79

Please sign in to comment.