You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
901 B
26 lines
901 B
3 years ago
|
import BN from "bn.js";
|
||
|
import { Address, Cell, CellMessage, InternalMessage, CommonMessageInfo } from "ton";
|
||
3 years ago
|
import Prando from "prando";
|
||
|
|
||
3 years ago
|
export const zeroAddress = new Address(0, Buffer.alloc(32, 0));
|
||
|
|
||
3 years ago
|
export function randomAddress(seed: string, workchain?: number) {
|
||
3 years ago
|
const random = new Prando(seed);
|
||
|
const hash = Buffer.alloc(32);
|
||
|
for (let i = 0; i < hash.length; i++) {
|
||
|
hash[i] = random.nextInt(0, 255);
|
||
|
}
|
||
3 years ago
|
return new Address(workchain ?? 0, hash);
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
export function internalMessage(params: { from?: Address; to?: Address; value?: BN; bounce?: boolean; body?: Cell }) {
|
||
|
const message = params.body ? new CellMessage(params.body) : undefined;
|
||
|
return new InternalMessage({
|
||
3 years ago
|
from: params.from ?? randomAddress("seed"),
|
||
3 years ago
|
to: params.to ?? zeroAddress,
|
||
|
value: params.value ?? 0,
|
||
|
bounce: params.bounce ?? true,
|
||
|
body: new CommonMessageInfo({ body: message }),
|
||
|
});
|
||
|
}
|