let user = User.load(userId)
if (user === null) {
user = new User(userId)
}
event.block.timestamp.toI32()
userPairBalance.balance.minus(value)
userPairBalance.balance.plus(value)
let tokenContract = TokenContract.bind(event.address);
token.contentURI = tokenContract.tokenURI(event.params.tokenId);
let craftmanAddress = '0x0000000';
let craftmanContract = Craftman.bind(Address.fromString(craftmanAddress));
let poolInfo = craftmanContract.try_poolInfo(event.params.pid);
if (poolInfo.reverted) {
log.info('poolInfo reverted', [])
} else {
log.info('callResult lptoken {}', [poolInfo.value.value0.toHexString()])
}
let pair = Pair.load(pairAddress.toHexString())
user.pair = pair.id
type UserPairBalance @entity {
id: ID!
pair: Pair!
}
type Pair @entity {
...
}
要用 null 判斷 entity 是否存過,不能用 or
設定屬性不能用 or 要直接寫在 === null 判斷內。
另外如果變數沒用到還是要註解,不然仍會編譯進去產生錯誤
let userPairBalance = UserPairBalance.load(userPairBalanceId)
let userPairBalanceCurrent = userPairBalance.balance || BigDecimal.fromString('0')
if (userPairBalance !== null) {
userPairBalance = new UserPairBalance(userPairBalanceId)
if(type === "fromUser") {
userPairBalance.balance = userPairBalanceCurrent.minus(value)
}
if(type === "toUser") {
userPairBalance.balance = userPairBalanceCurrent.plus(value)
}
}
let userPairBalance = UserPairBalance.load(userPairBalanceId)
if (userPairBalance !== null) {
if(type === "fromUser") {
userPairBalance.balance = userPairBalance.balance.minus(value)
}
if(type === "toUser") {
userPairBalance.balance = userPairBalance.balance.plus(value)
}
}
if (userPairBalance === null) {
userPairBalance = new UserPairBalance(userPairBalanceId)
userPairBalance.balance = value
}