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

comments

parent 86904fb2
......@@ -9,6 +9,7 @@ import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddr
import { DEFAULT_RPC_URL } from '../constants/defaultRpcUrl'
import { prepareWriteAttestation } from '../lib/prepareWriteAttestation'
import { writeAttestation } from '../lib/writeAttestation'
import { castAsDataType } from '../lib/castAsDataType'
import { dataTypeOptionValidator } from '../types/DataTypeOption'
const zodAddress = () =>
......@@ -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 {
const preparedTx = await prepareWriteAttestation(
parsedOptions.about,
parsedOptions.key,
castAsDataType(parsedOptions.value),
castAsDataType(parsedOptions.value, parsedOptions.dataType),
network.chainId
)
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