Skip to content

Commit

Permalink
Merge pull request #1839 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Merge develop into testnet
  • Loading branch information
Keith-CY authored Jan 6, 2025
2 parents c81fefe + 97510b0 commit afcdb87
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/Decoder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hexToUtf8 } from '../../utils/string'
import { useSetToast } from '../Toast'
import { ReactComponent as CopyIcon } from '../../assets/copy_icon.svg'
import styles from './styles.module.scss'
import { parseSporeCellData } from '../../utils/spore'
import { parseSporeCellData, parseSporeClusterData } from '../../utils/spore'
import { parseBtcTimeLockArgs } from '../../utils/rgbpp'

enum DecodeMethod {
Expand All @@ -18,6 +18,7 @@ enum DecodeMethod {
TokenInfo = 'token-info',
XudtData = 'xudt-data',
BTCTimeLock = 'btc-time-lock',
SporeCluster = 'spore-cluster',
Spore = 'spore',
JSON = 'json',
}
Expand Down Expand Up @@ -217,6 +218,10 @@ const Decoder = () => {
const script = addressToScript(v)
return { display: JSON.stringify(script, null, 2), copy: script }
}
case DecodeMethod.SporeCluster: {
const data = parseSporeClusterData(v)
return { display: jsonToList(data), copy: data }
}
case DecodeMethod.Spore: {
const data = parseSporeCellData(v)
switch (data.contentType) {
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@
"token-info": "Token Info",
"xudt-data": "XUDT Data",
"btc-time-lock": "BTC Time Lock",
"spore-cluster": "Spore Cluster",
"spore": "Spore",
"json": "JSON",
"select-x-from-y": "Selected {{x}} chars from {{y}}",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@
"token-info": "Token Info",
"xudt-data": "XUDT Data",
"btc-time-lock": "BTC Time Lock",
"spore-cluster": "Spore Cluster",
"spore": "Spore",
"json": "JSON",
"select-x-from-y": "从 {{y}} 字符起选择了 {{x}} 个字符",
Expand Down
16 changes: 15 additions & 1 deletion src/utils/spore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ export function parseSporeClusterData(hexData: string) {

const name = hexToUtf8(`0x${data.slice(nameOffset + 8, descriptionOffset)}`)
const description = hexToUtf8(`0x${data.slice(descriptionOffset + 8)}`)

try {
const parsed = JSON.parse(description)
if (typeof parsed === 'object') {
const v: Record<string, string> = { name }
Object.keys(parsed).forEach(key => {
if (key === 'name') {
throw new Error('name key is reserved')
}
v[key] = JSON.stringify(parsed[key], null, 2)
})
return v
}
} catch {
// ignore
}
return { name, description }
}

Expand Down

0 comments on commit afcdb87

Please sign in to comment.