-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Extra Currency via Ton Connect
- Loading branch information
1 parent
7691efd
commit e99aeca
Showing
6 changed files
with
92 additions
and
50 deletions.
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
packages/core/src/service/ton-blockchain/encoder/encoder-base.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Address } from '@ton/core/dist/address/Address'; | ||
import { Cell } from '@ton/core/dist/boc/Cell'; | ||
import { Dictionary } from '@ton/core/dist/dict/Dictionary'; | ||
import type { CurrencyCollection } from '@ton/core/dist/types/CurrencyCollection'; | ||
import type { MessageRelaxed } from '@ton/core/dist/types/MessageRelaxed'; | ||
import type { StateInit } from '@ton/core/dist/types/StateInit'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
export abstract class EncoderBase { | ||
private getOtherDict = () => { | ||
return Dictionary.empty(Dictionary.Keys.Uint(32), Dictionary.Values.BigVarUint(5)); | ||
}; | ||
|
||
protected currencyValue(src: { | ||
amount: string | number; | ||
extraCurrencies: | ||
| { | ||
id: number; | ||
value: string; | ||
}[] | ||
| undefined; | ||
}): CurrencyCollection { | ||
const coins = BigInt(src.amount); | ||
|
||
if (!src.extraCurrencies) { | ||
return { coins }; | ||
} | ||
|
||
const other = this.getOtherDict(); | ||
|
||
for (let extra of src.extraCurrencies) { | ||
other.set(extra.id, BigInt(extra.value)); | ||
} | ||
|
||
return { coins, other }; | ||
} | ||
|
||
protected extraCurrencyValue(src: { id: number; weiAmount: BigNumber }): CurrencyCollection { | ||
const other = this.getOtherDict(); | ||
|
||
other.set(src.id, BigInt(src.weiAmount.toFixed(0))); | ||
|
||
return { coins: BigInt('0'), other }; | ||
} | ||
|
||
protected internalMessage(src: { | ||
to: Address; | ||
value: CurrencyCollection; | ||
bounce: boolean; | ||
init?: StateInit; | ||
body?: Cell; | ||
}): MessageRelaxed { | ||
return { | ||
info: { | ||
type: 'internal', | ||
dest: src.to, | ||
value: src.value, | ||
bounce: src.bounce, | ||
ihrDisabled: true, | ||
bounced: false, | ||
ihrFee: 0n, | ||
forwardFee: 0n, | ||
createdAt: 0, | ||
createdLt: 0n | ||
}, | ||
init: src.init ?? undefined, | ||
body: src.body ?? Cell.EMPTY | ||
}; | ||
} | ||
} |
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
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
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