Corda Account:列“中的错误空值”;id";违反非空约束
我正在测试Corda 4.3,该帐户运行在具有区域限制的开放源代码上。Corda Account:列“中的错误空值”;id";违反非空约束,corda,Corda,我正在测试Corda 4.3,该帐户运行在具有区域限制的开放源代码上。 我有4个节点,分别是节点A、节点B、节点C和公证人(公证人是Corda 4.1的CE版本),并使用PostgreSQL作为数据库 首先,我在节点A上创建一个帐户testadm1,并与节点B共享 然后我在节点B上创建一个帐户seller1和seller2,并与节点A共享 使用以下流程 CreateAccountFlow @StartableByRPC @StartableByService @InitiatingFlow cl
我有4个节点,分别是节点A、节点B、节点C和公证人(公证人是Corda 4.1的CE版本),并使用PostgreSQL作为数据库 首先,我在节点A上创建一个帐户testadm1,并与节点B共享
然后我在节点B上创建一个帐户seller1和seller2,并与节点A共享 使用以下流程 CreateAccountFlow
@StartableByRPC
@StartableByService
@InitiatingFlow
class CreateNewAccount(private val acctName:String) : FlowLogic<String>() {
@Suspendable
override fun call(): String {
//Create a new account
val newAccount = accountService.createAccount(name = acctName).toCompletableFuture().getOrThrow()
val acct = newAccount.state.data
return ""+acct.name + " team's account was created. UUID is : " + acct.identifier
}
}
@StartableByRPC
@StartableByService
@InitiatingFlow
class ShareAccountTo(private val acctNameShared: String,
private val shareTo: Party) : FlowLogic<String>(){
@Suspendable
override fun call(): String {
//Create a new account
val allmyAccounts = accountService.ourAccounts()
val sharedAccount = allmyAccounts.single { it.state.data.name == acctNameShared }.state.data.identifier.id
accountService.shareAccountInfoWithParty(sharedAccount,shareTo)
return "Shared " + acctNameShared + " with " + shareTo.name.organisation
}
}
这就是StateA的样子
@BelongsToContract(StateAContract::class)
data class StateA(
val buyer: AnonymousParty,
val documentNumber: String,
val issuedDate: Instant = Instant.now(),
val lifecycle: StateAContract.Lifecycle,
val seller: AnonymousParty,
val amount: BigDecimal,
override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState, QueryableState {
override val participants: List<AbstractParty> get() = listOf(buyer, seller)
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(StateASchema)
override fun generateMappedObject(schema: MappedSchema): PersistentState {
if (schema is StateASchema) {
return StateASchema.StateAEntity(
buyer = buyer,
documentNumber = documentNumber,
issuedDate = issuedDate,
lifecycle = lifecycle.toString(),
seller = seller,
amount = amount.quantity
)
} else {
throw IllegalStateException("Cannot construct instance of ${this.javaClass} from Schema: $schema")
}
}
}
我已经检查了我的postgres数据库,看到节点A在account表中使用此sql拥有节点B的帐户
select * from accounts
join vault_states
on vault_states.transaction_id = accounts.transaction_id
and vault_states.output_index = accounts.output_index
and vault_states.state_status = 0
我做错了什么,还是遗漏了什么?我怀疑这是您的
generateMappedObject
函数。我认为您不想返回StateA
,因为它不是PersistentState
。您能否创建一个PersistentState
并返回它
请参阅以获取示例。我找到了根本原因
首先,我以Corda版本4.1启动该节点,它创建表pk\U hash\U to\U ext\U id\U map table,其中包含3列external\U id、public\U key\U hash和id(非空)
但我将Corda版本更改为4.3,而不在数据库上执行任何操作。我认为在4.3中,它不再需要id,所以当它尝试将id放入数据库时,它会将id发送为null
因此,我要做的是清除数据库并重新启动所有节点,现在pk_hash_to_ext_id_映射表,带有两列external_id,public_key_hash,现在它通过了。generateMappedObject函数中的StateA是模式中的实体,可能名称混淆了,我没有显示我的模式。我已经更新了模式文件并修复了命名。那么您的
帐户表有什么功能?特别是对于名称为67cd26fc-fe02-4c9e-8c9a-b98f41496e8f的账户
?该错误表示id
为null
。这就是你在桌子上看到的吗?太好了。很高兴你把它整理好了。
@BelongsToContract(StateAContract::class)
data class StateA(
val buyer: AnonymousParty,
val documentNumber: String,
val issuedDate: Instant = Instant.now(),
val lifecycle: StateAContract.Lifecycle,
val seller: AnonymousParty,
val amount: BigDecimal,
override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState, QueryableState {
override val participants: List<AbstractParty> get() = listOf(buyer, seller)
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(StateASchema)
override fun generateMappedObject(schema: MappedSchema): PersistentState {
if (schema is StateASchema) {
return StateASchema.StateAEntity(
buyer = buyer,
documentNumber = documentNumber,
issuedDate = issuedDate,
lifecycle = lifecycle.toString(),
seller = seller,
amount = amount.quantity
)
} else {
throw IllegalStateException("Cannot construct instance of ${this.javaClass} from Schema: $schema")
}
}
}
object StateSchema
object StateASchema : MappedSchema(
schemaFamily = StateSchema::class.java,
version = 1,
mappedTypes = listOf(StateA::class.java)
)
@Entity
@Table(name = "stateA")
data class StateAEntity(
@Column(name = "linear_id")
var linearId: String? = null,
@Column(name = "buyer")
val buyer: AbstractParty? = null,
@Column(name = "external_id")
var documentNumber: String? = null,
@Column(name = "issued_date")
var issuedDate: Instant? = null,
@Column(name = "seller")
val seller: AbstractParty? = null,
@Column(name = "amount")
val amount: BigDecimal? = null
) : PersistentState()
select * from accounts
join vault_states
on vault_states.transaction_id = accounts.transaction_id
and vault_states.output_index = accounts.output_index
and vault_states.state_status = 0