Skip to content

Commit

Permalink
payment channels
Browse files Browse the repository at this point in the history
  • Loading branch information
tolya-yanot committed Jul 29, 2022
1 parent 8064062 commit a5475c3
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dist/tonweb.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tonweb",
"version": "0.0.50",
"version": "0.0.51",
"description": "TonWeb - JavaScript API for TON blockchain",
"main": "src/index.js",
"types": "dist/types/index.d.ts",
Expand Down
20 changes: 8 additions & 12 deletions src/contract/dns/Dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const {
} = require("./DnsUtils");

// Need to get this address from network Config #4
const rootDnsAddress = 'Ef_BimcWrQ5pmAWfRqfeVHUCNV8XgsLqeAMBivKryXrghFW3';
const testnetRootDnsAddress = 'Ef-HFfj4yDgk71cegsSLlcuXpHtxcT0yPp33gh-VZLT5UQpX';
const mainnetRootDnsAddress = '-1:5555555555555555555555555555555555555555555555555555555555555555';

class Dns {
/**
Expand All @@ -27,10 +28,10 @@ class Dns {
* @returns {Promise<Address>}
*/
async getRootDnsAddress() {
if (this.provider.host.indexOf('testnet') === -1) { // mainnet
return null;
if (this.provider.host.indexOf('testnet') > -1) {
return new Address(testnetRootDnsAddress);
}
return new Address(rootDnsAddress);
return new Address(mainnetRootDnsAddress);
}

/**
Expand All @@ -39,21 +40,16 @@ class Dns {
* @param oneStep {boolean | undefined} non-recursive
* @returns {Promise<Cell | Address | BN | null>}
*/
resolve(domain, category, oneStep) {
if (this.provider.host.indexOf('testnet') === -1) { // mainnet
return null;
}
return dnsResolve(this.provider, rootDnsAddress, domain, category, oneStep)
async resolve(domain, category, oneStep) {
const rootDnsAddress = await this.getRootDnsAddress();
return dnsResolve(this.provider, rootDnsAddress.toString(), domain, category, oneStep)
}

/**
* @param domain {string} e.g "sub.alice.ton"
* @returns {Promise<Address | null>}
*/
getWalletAddress(domain) {
if (this.provider.host.indexOf('testnet') === -1) { // mainnet
return null;
}
return this.resolve(domain, DNS_CATEGORY_WALLET);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/contract/dns/DnsCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DnsCollection extends Contract {
*/
constructor(provider, options) {
options.wc = 0;
options.code = options.code || Cell.oneFromBoc('B5EE9C724102170100020E000114FF00F4A413F4BCF2C80B0102016202030202CC0405020120111202012006070201D40F1002012008090201200D0E01F543221C70094840FF2F0DED0D3030171B0915BE0FA403001D31FED44D0D4D4303122C0008E5032F00320D74920C218F2E0C8208103F0BBF2E0C978A908C000F2E0CA20F004F2E0CB20F9018050F833206EB38E10D0F4043052108307F40E6FA131F2D0CC9130E2C858CF16C9C85004CF1613CCC9F009E010235F0380A0201200B0C000EC007DC840FF2F000331C27C074C1C07000082CE500A98200B784B98C4830003CB43260004F3223880875D244B5C61673C58875D2883000082CE6C070007CB83280B50C3400A44C78B98C727420007F47021D7498E355CBA20B38E2E3002D30721C02D23C200B024A6F85240B9B022C22F23C13AB0B122C26003C17B13B012B1B320B39402A60802DE13DEE66C12BA8002D501C8CBFFF828CF16C97020C8CB0113F400F400CB00C98001B3E401D3232C084B281F2FFF274200039167C01DC087C021DE0063232C15633C59C3E80B2DAF3333260103EC020020120131402012015160007B8B5D318001FBA7A3ED44D0D4D43031F0077001F00880019B905BED44D0D4D4303070016D8009DBA30C3020D74978A908C000F2E04620D70A07C00021D749C0085210B0935B786DE0209501D3073101DE21F0025122D71830F9018200BA93C8CB0F01820167A3ED43D8CF16C90191789170E212A0018467EBCAB');
options.code = options.code || Cell.oneFromBoc('B5EE9C7241021D010002C7000114FF00F4A413F4BCF2C80B0102016202030202CC040502012017180201200607020120131402012008090201200D0E016D420C70094840FF2F0DE01D0D3030171B0925F03E0FA403001D31FED44D0D4D4303122C000E30210245F048210370FEC51BADC840FF2F080A0201200B0C00D032F82320821062E4270CBCF2E0C701F00420D74920C218F2E0C8208103F0BBF2E0C92078A908C000F2E0CA21F005F2E0CB58F00714BEF2E0CC22F90180B0F833206EB38E10D0F4043052108307F40E6FA131F2D0CC9130E2C85004CF16C9C85003CF1612CCC9F00C000D1C3232C072742000331C27C074C1C07000082CE500A98200B784B98C4830003CB432600201200F100201201112004F3223880875D244B5C61673C58875D2883000082CE6C070007CB83280B50C3400A44C78B98C727420007F1C0875D2638D572E882CE38B8C00B4C1C8700B48F0802C0929BE14902E6C08B08BC8F04EAC2C48B09800F05EC4EC04AC6CC82CE500A98200B784F7B99B04AEA00093083001258C2040FA201938083001658C20407D200CB8083001A58C204064200A38083001E58C20404B2007B8083002258C204032200538083002650C20191EB83002A4E00C9D781E9C600069006AC0BC018060840EE6B2802A0060840EE6B2802A00A08418B909C328608209E3402A410830856456F81B04A5A9D6A0192A41392002015815160039D2CF8053810F805BBC00C646582AC678B387D0165B5E66664C0207D804002D007232FFFE0A33C5B25C083232C044FD003D0032C03260001B3E401D3232C084B281F2FFF27420020120191A0201201B1C0007B8B5D318001FBA7A3ED44D0D4D43031F00A7001F00B8001BB905BED44D0D4D430307FF002128009DBA30C3020D74978A908C000F2E04620D70A07C00021D749C0085210B0935B786DE0209501D3073101DE21F0035122D71830F9018200BA93C8CB0F01820167A3ED43D8CF16C90191789170E212A00180CEC2BAE');
super(provider, options);

if (!options.collectionContent && !options.address) throw new Error('required collectionContent cell');
Expand Down Expand Up @@ -42,10 +42,11 @@ class DnsCollection extends Contract {
const myAddress = await this.getAddress();
const result = await this.provider.call2(myAddress.toString(), 'get_collection_data');

const nextItemIndex = result[0].toNumber();
const collectionContent = result[1];
const collectionContentUri = parseOffchainUriCell(collectionContent);

return {collectionContentUri, collectionContent, ownerAddress: null, nextItemIndex: 0};
return {collectionContentUri, collectionContent, ownerAddress: null, nextItemIndex};
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/contract/dns/DnsItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {Address, BN} = require("../../utils");
const {parseAddress} = require('./../token/nft/NftUtils.js');
const {dnsResolve, categoryToBN} = require("./DnsUtils.js")

const DNS_ITEM_CODE_HEX = 'B5EE9C7241022C010006F8000114FF00F4A413F4BCF2C80B0102016202030202CC0405020120232402012006070201481F2002014808090201201B1C03F7007434C0C05C6C2497C1383E903E900C7E800C5C75C87E800C7E800C3C0249ECF8C094D671C1462C238CC426D7C2FE900C1C14C01B60101C20043232C15401F3C594017E808572DA84B2C7F2CFC89BACE51633C5C0644CB88072407EC0380A71C0245C254274C7D42AB8887C01FE08C86F09300038C08C4374CFC9600A0B0C00113E910C1C2EBCB8536002FC5F056C22355242C705F2E19501FA40D4306D21D08B42E746F6E8F00682F082A3537FF0DBCE7EEC35D69EDC3A189EE6F17D82F353A553F9AA96CB0BE3CE89588307F4168BA544F4E20446F6D61696E86DF00682F0C9046F7A37AD0EA7CEE73355984FA5428982F8B37C8F7BCEC91F7AC71A7CD104588307F4168922D0F0060D0E013C343A3A3B8E1636363737375135C705F2E196102510241023F823F00AE30E0F03FC6EB31FB08E5A343652DDA1820AFAF0805210A15260BC9835820AFAF08015A1923004E220C2FF8E2F77706D722951454434708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00DE0C6D0DA150CC0B04923E5BE2F82328A18209E14320BC226EB0E30282105FCC3D145210BAE302101112003A68747470733A2F2F646E732E746F6E2E6F72672F69636F6E2E706E672300C682F06105D6CC76AF400325E94D588CE511BE5BFDBB73B437DC51ECA43917D7A43E3D588307F41670C8CB07F400C981012C8050F833206EB38E14D0F4043070018307F40E6FA19431D31F309130E29130E2F82301A0F0054466F00810351034F823F00A00F0302680698064A98452A0BCF2E197820AFAF08052B0A15270BC9836820AFAF0801AA1933A0905E220C2FF8E2C70206D21105B708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00923036E27A23F823A1A120C2009313A0029130E24464F00810451024F823F00A00305B6C55F005F82381012CA04470F0081045103412F823F00A0128305383C705F2E191105A104910381027103655021303FE82102FCB26A25210BA8E3F5F0535365B7082108B77173505C8CBFF5003CF164440138040708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00E082101A0B9D515210BA8E193032353537375135C705F2E19A03D4304015045033F823F00AE020C00AE3023A09C00BE3025F0B840F14151603F63603FA4021F001FA40D20031FA00820AFAF0801EA121945315A0A1DE22D70B01C300209206A19136E220C2FFF2E192218E3E821005138D91C8500CCF16500ECF1671244C145449D0708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00107A94102D3A5BE202E30F105618191A0086303739395155C705F2E19B05D3FF20D74AC20009D0D30701C000F2E19CF404300999D430D040188307F416983050078307F45B30E270C8CB07F400C91045034444F00A01DA8050F833D0F4043052508307F40E6FA18ED7D30721C0008E932510BD107A09105810471046105C4313504C1D96303B5F036C61E201C0018E2D7053006D8100A0708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB009130E2925F0CE2170004F2F003F83603FA4021F001FA40D20031FA00820AFAF0801EA121945315A0A1DE22D70B01C300209206A19136E220C2FFF2E192218E3E821005138D91C8500CCF16500ECF1671244C145449D0708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00107A94102D3A5BE202E30F10560118191A006A29F0018210D53276DB103A47046D71708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00000A10293335300010104510344033F00A000D570C8CB01C9D080201201D1E00531C3232C1C8B3C5885BACE385C0B5D24875D2682040FDEEE4B3C5A5F20073C5B2407338A49B0878B274200021081BA50C1B5C0838343E903E8034CFCC200201202122002B406C8CBFF5005CF165003CF16CCCCF400CB3FC9ED5480017321400F3C5807E80B2CFF26000513B513434FFFE900835D2708027DFC07E9035353D0134CFCC0415C415B80C1C1B5B5B5B490415C415A0020120252602012027280013BBB39F009175F07F0078000DBA559F0096C718000DB8FCFF0095F038020120292A0013B64A5E012204EBE0FA1001FBB461843AE9240F152118001E5C08DE012206EBE0FA1A60E038001E5C339E8086047AE140E68078001E5C33B80111C344180012660F003C003060FE81CDF432CF190B19E2D93C060F0DBC06105E033E04883DCB11FB64DDC4964AD1BA06B879240DC23572F37CC5CAAAB143A2FFE03060FE81CDF432CF190B19E2D93C06102B0004786DA9E7FD01';
const DNS_ITEM_CODE_HEX = 'B5EE9C7241022801000696000114FF00F4A413F4BCF2C80B0102016202030202CC04050201201E1F02012006070201481819020120080902015816170201200A0B000D470C8CB01C9D0801F73E09DBC400B434C0C05C6C2497C1383E903E900C7E800C5C75C87E800C7E800C3C0289ECE39397C15B088D148CB1C17CB865407E90350C1B5C3232C1FD00327E08E08418B909C328608209E3402A4108308324CC200337A0404B20403C162A20032A41287E08C0683C00911DFC02440D7E08FC02F814D671C1462C200C00113E910C1C2EBCB8536003F88E34109B5F0BFA40307020F8256D8040708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00E029C70091709509D31F50AAE221F008F82321BC24C0008E9E343A3A3B8E1636363737375135C705F2E196102510241023F823F00BE30EE0310DD33F256EB31FB0926C21E30D0D0E0F00FE302680698064A98452B0BEF2E19782103B9ACA0052A0A15270BC993682103B9ACA0019A193390805E220C2008E328210557CEA20F82510396D71708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00923036E2803C23F823A1A120C2009313A0029130E24474F0091024F823F00B00D2343653CDA182103B9ACA005210A15270BC993682103B9ACA0016A1923005E220C2008E378210370FEC516D72295134544743708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB001CA10B9130E26D5477655477632EF00B0204C882105FCC3D145220BA8E9531373B5372C705F2E191109A104910384706401504E082101A0B9D515220BA8E195B32353537375135C705F2E19A03D4304015045033F823F00BE02182104EB1F0F9BAE3023B20821044BEAE41BAE302382782104ED14B65BA1310111200885B363638385147C705F2E19B04D3FF20D74AC20007D0D30701C000F2E19CF404300798D43040168307F417983050058307F45B30E270C8CB07F400C910354014F823F00B01FE30363A246EF2E19D80B0F833D0F4043052408307F40E6FA1F2E19FD30721C00022C001B1F2E1A021C0008E9124109B1068517A10571046105C43144CDD9630103A395F07E201C0018E32708210370FEC51586D8100A0708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00915BE21301FE8E7A37F8235006A1810258BC066E16B0F2E19E23D0D749F823F0075290BEF2E1975178A182103B9ACA00A120C2008E32102782104ED14B6558076D72708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB0093303535E2F82381012CA0F0024477F0091045103412F823F00BE05F041501F03502FA4021F001FA40D20031FA0082103B9ACA001DA121945314A0A1DE22D70B01C300209205A19135E220C2FFF2E192218E3E821005138D91C8500BCF16500DCF1671244B145448C0708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00106994102C395BE20114008A8E3528F0018210D53276DB103946096D71708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB0093383430E21045103412F823F00B009A32353582102FCB26A2BA8E3A7082108B77173504C8CBFF5005CF161443308040708010C8CB055007CF165005FA0215CB6A12CB1FCB3F226EB39458CF17019132E201C901FB00E05F04840FF2F00093083001258C2040FA201938083001658C20407D200CB8083001A58C204064200A38083001E58C20404B2007B8083002258C204032200538083002650C20191EB83002A4E00C9D781E9C600069006AC0BC018060840EE6B2802A0060840EE6B2802A00A08418B909C328608209E3402A410830856456F81B04A5A9D6A0192A4139200201201A1B0201201C1D0021081BA50C1B5C0838343E903E8034CFCC200017321400F3C5807E80B2CFF26000513B513434FFFE900835D2708027DFC07E9035353D0134CFCC0415C415B80C1C1B5B5B5B490415C415A0002B01B232FFD40173C59400F3C5B3333D0032CFF27B5520020120202102012024250013BBB39F00A175F07F008802027422230010A874F00A10475F07000CA959F00A6C71000DB8FCFF00A5F03802012026270013B64A5E014204EBE0FA1000C3B461843AE9240F152118001E5C08DE014206EBE0FA1A60E038001E5C339E8086007AE140F8001E5C33B84111C466105E033E04883DCB11FB64DDC4964AD1BA06B879240DC23572F37CC5CAAAB143A2FFFBC4180012660F003C003060FE81E60F0030C385AB59';

class DnsItem extends Contract {
/**
Expand Down Expand Up @@ -129,7 +129,7 @@ class DnsItem extends Contract {
*/
DnsItem.createChangeContentEntryBody = async (params) => {
const body = new Cell();
body.bits.writeUint(10, 32); // OP
body.bits.writeUint(0x4eb1f0f9, 32); // OP
body.bits.writeUint(params.queryId || 0, 64); // query_id
body.bits.writeUint(await categoryToBN(params.category), 256);
if (params.value) {
Expand Down
6 changes: 5 additions & 1 deletion src/contract/dns/DnsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ const domainToBytes = (domain) => {
}
});

const rawDomain = '\0' + arr.reverse().join('\0') + '\0';
let rawDomain = arr.reverse().join('\0') + '\0';
if (rawDomain.length < 126) {
rawDomain = '\0' + rawDomain;
}

return new TextEncoder().encode(rawDomain);
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TransportWebUSB = require("@ledgerhq/hw-transport-webusb").default;
const TransportWebHID = require("@ledgerhq/hw-transport-webhid").default;
const BluetoothTransport = require("@ledgerhq/hw-transport-web-ble").default;
const {Dns, DnsCollection, DnsItem} = require("./contract/dns").default;
const version = '0.0.50';
const version = '0.0.51';

class TonWeb {
constructor(provider) {
Expand Down
Loading

0 comments on commit a5475c3

Please sign in to comment.