Created
May 20, 2018 19:46
-
-
Save perfect-cents/b7a8ed9c90df56bb51e0341796ebdcb8 to your computer and use it in GitHub Desktop.
A couple ideas about a potential browseth framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// chainId, nonce, from | |
// should be determined in the send and call functions respectivly | |
interface ToStringable { | |
toString(): string; | |
} | |
type Data = string | ToStringable; | |
type Quantity = number | string | ToStringable; | |
type Block = Quantity; | |
interface TransactionObject { | |
value?: Quantity; | |
to?: Data; | |
data?: Data; | |
UNSAFE_gas?: Quantity; | |
UNSAFE_gasPrice?: Quantity; | |
UNSAFE_nonce?: Quantity; | |
} | |
interface RawRequest { | |
url: string; | |
body: object; | |
headers: [string, string | string[]][]; | |
timeout: number; | |
[key: string]: any; | |
} | |
declare const config: { | |
baseUrl: string; // defaults to http://localhost:8545 | |
gasPrice: Quantity | (() => Quantity | Promise<Quantity>); // defaults to 2 gwei // should be hooked onto every change in baseUrl | |
chainId: Quantity | (() => Quantity | Promise<Quantity>); // should be hooked onto every change in baseUrl | |
defaultBlock: Block | (() => Block | Promise<Block>); | |
contracts: { | |
[key: string]: { | |
address: string; | |
bin: string; | |
jsonInterface: string | any[]; | |
}; | |
}; | |
UNSAFE_advanced: { | |
hydrateCallTransactionObject(obj: TransactionObject): TransactionObject; | |
hydrateOfflineSendTransactionObject( | |
obj: TransactionObject, | |
): TransactionObject; | |
hydrateOnlineSendTransactionObject( | |
obj: TransactionObject, | |
): TransactionObject; | |
serialize(transaction: TransactionObject): RawRequest; | |
deserialize(response: RawRequest): any; | |
handle(request: RawRequest, cb: (error: Error, response: any) => void); | |
}; | |
}; | |
declare const exposedApi: { | |
send(transaction: SendTransaction | CallTransaction): void; | |
setOnlineWallet(baseRequest?: Partial<RawRequest>); | |
setWeb3Wallet(web3Provider): void; // defaults to window.web3.currentProvider | |
setSignerWallet(signer, baseRequest?: Partial<RawRequest>): void; // uses the baseUrl as a fallback | |
contracts: { | |
[key: string]: { | |
options: { | |
defaultAddress: string; | |
}; | |
f: { | |
[key: string]: { | |
Call: object; | |
Send: object; | |
}; | |
}; | |
}; | |
}; | |
explorer: { | |
transaction: { | |
reciept(hash: Data): Promise<any>; | |
byBlockAndIndex(block: Block, index: Quantity): Promise<any>; | |
byHash(hash: Data): Promise<any>; | |
}; | |
block(block: Block): Promise<any>; | |
}; | |
}; | |
abstract class SendTransaction { | |
static isSendTransaction = {}; | |
constructor(public value: TransactionObject) {} | |
willSend?(): void; | |
abstract didSend(hash: string): void; | |
abstract didCatch(error: Error, metaData?: any): void; | |
didResolve?(success: boolean, receipt: object, events?: any[]): void; | |
} | |
abstract class CallTransaction { | |
static isCallTransaction = {}; | |
constructor(public value: TransactionObject) {} | |
willSend?(): void; | |
abstract didSend(result: string): void; | |
abstract didCatch(error: Error, metaData?: any): void; | |
} | |
abstract class SendCancelTransaction extends SendTransaction { | |
static isSendCancelTransaction = {}; | |
constructor(nonce: number | string) { | |
super({ | |
UNSAFE_nonce: nonce, | |
}); | |
} | |
} | |
const queuedTransactions: Array<SendTransaction | CallTransaction> = []; | |
function send(transaction: SendTransaction | CallTransaction) { | |
queuedTransactions.push(transaction); | |
} | |
function sendOne(...args) {} | |
function flush(): never { | |
while (true) { | |
const transaction = queuedTransactions.shift(); | |
sendOne(transaction); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment