Skip to content

Commit

Permalink
fix: price functions
Browse files Browse the repository at this point in the history
  • Loading branch information
reedrosenbluth committed Apr 7, 2021
1 parent d6f64b3 commit a79c5e8
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions packages/bns/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import {
makeRandomPrivKey,
broadcastTransaction,
bufferCV,
callReadOnlyFunction,
ClarityType,
ClarityValue,
cvToString,
getAddressFromPrivateKey,
hash160,
makeContractCall,
makeRandomPrivKey,
privateKeyToString,
ResponseErrorCV,
SignedContractCallOptions,
standardPrincipalCV,
ClarityValue,
ClarityType,
ResponseErrorCV,
bufferCV,
privateKeyToString,
getAddressFromPrivateKey,
broadcastTransaction,
TxBroadcastResultRejected,
TxBroadcastResult, hash160
TxBroadcastResult,
TxBroadcastResultRejected
} from '@stacks/transactions';

import {
StacksNetwork,
StacksMainnet
} from '@stacks/network';
import {StacksMainnet, StacksNetwork} from '@stacks/network';

import {
decodeFQN,
bufferCVFromString,
uintCVFromBN, getZonefileHash
} from './utils'
import {bufferCVFromString, decodeFQN, getZonefileHash, uintCVFromBN} from './utils'

import BN from 'bn.js';

Expand Down Expand Up @@ -190,10 +185,15 @@ export async function getNamespacePrice(
})
.then((responseCV: ClarityValue) => {
if (responseCV.type === ClarityType.ResponseOk) {
return new BN(responseCV.value.toString());
if (responseCV.value.type === ClarityType.Int ||
responseCV.value.type === ClarityType.UInt) {
return responseCV.value.value;
} else {
throw new Error('Response did not contain a number');
}
} else {
const errorResponse = responseCV as ResponseErrorCV;
throw new Error(errorResponse.value.toString());
throw new Error(cvToString(errorResponse.value));
}
})
}
Expand Down Expand Up @@ -233,10 +233,15 @@ export async function getNamePrice(
})
.then((responseCV: ClarityValue) => {
if (responseCV.type === ClarityType.ResponseOk) {
return new BN(responseCV.value.toString());
if (responseCV.value.type === ClarityType.Int ||
responseCV.value.type === ClarityType.UInt) {
return responseCV.value.value;
} else {
throw new Error('Response did not contain a number');
}
} else {
const errorResponse = responseCV as ResponseErrorCV;
throw new Error(errorResponse.value.toString());
throw new Error(cvToString(errorResponse.value));
}
})
}
Expand Down

0 comments on commit a79c5e8

Please sign in to comment.