Commit 6d6e407d authored by Will Cory's avatar Will Cory

comments

parent 86904fb2
...@@ -9,6 +9,7 @@ import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddr ...@@ -9,6 +9,7 @@ import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddr
import { DEFAULT_RPC_URL } from '../constants/defaultRpcUrl' import { DEFAULT_RPC_URL } from '../constants/defaultRpcUrl'
import { prepareWriteAttestation } from '../lib/prepareWriteAttestation' import { prepareWriteAttestation } from '../lib/prepareWriteAttestation'
import { writeAttestation } from '../lib/writeAttestation' import { writeAttestation } from '../lib/writeAttestation'
import { castAsDataType } from '../lib/castAsDataType'
import { dataTypeOptionValidator } from '../types/DataTypeOption' import { dataTypeOptionValidator } from '../types/DataTypeOption'
const zodAddress = () => const zodAddress = () =>
...@@ -82,29 +83,11 @@ export const write = async (options: WriteOptions) => { ...@@ -82,29 +83,11 @@ export const write = async (options: WriteOptions) => {
}), }),
}) })
const castAsDataType = (value: any) => {
if (parsedOptions.dataType === 'string') {
return value
} else if (parsedOptions.dataType === 'number') {
return Number(value)
} else if (parsedOptions.dataType === 'bool') {
return Boolean(value)
} else if (parsedOptions.dataType === 'bytes') {
return value
} else if (parsedOptions.dataType === 'address') {
return value
} else {
throw new Error(
`Unrecognized data type ${parsedOptions.dataType satisfies never}`
)
}
}
try { try {
const preparedTx = await prepareWriteAttestation( const preparedTx = await prepareWriteAttestation(
parsedOptions.about, parsedOptions.about,
parsedOptions.key, parsedOptions.key,
castAsDataType(parsedOptions.value), castAsDataType(parsedOptions.value, parsedOptions.dataType),
network.chainId network.chainId
) )
const result = await writeAttestation(preparedTx) const result = await writeAttestation(preparedTx)
......
import { DataTypeOption } from '../types/DataTypeOption'
/**
* @internal
* Takes a datatype and returns the value casted to that type
*/
export const castAsDataType = (value: any, dataType: DataTypeOption) => {
if (dataType === 'string') {
return value
} else if (dataType === 'number') {
return Number(value)
} else if (dataType === 'bool') {
return Boolean(value)
} else if (dataType === 'bytes') {
return value
} else if (dataType === 'address') {
return value
} else {
throw new Error(`Unrecognized data type ${dataType satisfies never}`)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment