我正在编写一个向 DA Ledger 发出请求的客户端。我正在遵循我在之前的文章Doing CRUD on the DA Ledger through a gRPC client中收到的建议。
我需要运行“GetTransactions”rpc。这样做需要 GetTransactionsRequest 对象。GetTransactionsRequest 对象有一个名为“filter”的必需属性,该属性是 TransactionFilter 类型。我无法创建满足我需求的事务过滤器。它的 .proto 文件是:
// Used for filtering Transaction and Active Contract Set streams.
// Determines which on-ledger events will be served to the client.
message TransactionFilter {
// Keys of the map determine which parties' on-ledger transactions are being queried.
// Values of the map determine which events are disclosed in the stream per party.
// At the minimum, a party needs to set an empty Filters message to receive any events.
// Required
map<string, Filters> filters_by_party = 1;
}
'filters_by_party' 的唯一字段是必需的。在 php 中设置该字段需要以下函数:
/**
* Keys of the map determine which parties' on-ledger transactions are being queried.
* Values of the map determine which events are disclosed in the stream per party.
* At the minimum, a party needs to set an empty Filters message to receive any events.
* Required
*
* Generated from protobuf field <code>map<string, .com.digitalasset.ledger.api.v1.Filters> filters_by_party = 1;</code>
* @param array|\Google\Protobuf\Internal\MapField $var
* @return $this
*/
public function setFiltersByParty($var)
{
$arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Com\Digitalasset\Ledger\Api\V1\Filters::class);
$this->filters_by_party = $arr;
return $this;
}
用于在 mapFiled 对象中设置值的 php 函数是:
/**
* Assign the element at the given key.
*
* This will also be called for: $arr[$key] = $value
*
* @param object $key The key of the element to be fetched.
* @param object $value The element to be assigned.
* @return void
* @throws ErrorException Invalid type for key.
* @throws ErrorException Invalid type for value.
* @throws ErrorException Non-existing key.
*/
public function offsetSet($key, $value)
{
$this->checkKey($this->key_type, $key);
switch ($this->value_type) {
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::INT32:
case GPBType::ENUM:
GPBUtil::checkInt32($value);
break;
case GPBType::FIXED32:
case GPBType::UINT32:
GPBUtil::checkUint32($value);
break;
case GPBType::SFIXED64:
case GPBType::SINT64:
case GPBType::INT64:
GPBUtil::checkInt64($value);
break;
case GPBType::FIXED64:
case GPBType::UINT64:
GPBUtil::checkUint64($value);
break;
case GPBType::FLOAT:
GPBUtil::checkFloat($value);
break;
case GPBType::DOUBLE:
GPBUtil::checkDouble($value);
break;
case GPBType::BOOL:
GPBUtil::checkBool($value);
break;
case GPBType::STRING:
GPBUtil::checkString($value, true);
break;
case GPBType::MESSAGE:
if (is_null($value)) {
trigger_error("Map element cannot be null.", E_USER_ERROR);
}
GPBUtil::checkMessage($value, $this->klass);
break;
default:
break;
}
$this->container[$key] = $value;
}
例如,我如何将当事方名称“dealer1”和“dealer2”设置为 filters_by_party 的当事方。我尝试了以下代码:
$parties= new Google\Protobuf\Internal\MapField(Google\Protobuf\Internal\GPBType::STRING,Google\Protobuf\Internal\GPBType::MESSAGE);
$parties->offsetSet(0,"dealer1");
$parties->offsetSet(1,"dealer2");
导致以下错误:
PHP Fatal error: Given value is not message. in /home/vantage/damlprojects/loaner_car/php/ledger_client.php on line 85
我不明白为什么 filter_by_party 'set' 函数需要'message'。我不知道如何以“消息”的形式写经销商名称。似乎做一些应该很简单的事情却很复杂。将输入 $var 设置为“setFiltersByParty”函数的正确方法是什么?