交易数据保存在哪里?
Where is the data of a transaction saved?
为了介绍我的问题,我想举个例子。假设一位顾客想加入健身房。交易已发送并包含:
- 客户编号
- 姓名
- 开始日期
- 结束日期
智能合约接收交易并在健身房创建会员资格。这些数据保存在哪里?一段时间后,我想验证订阅是否已过期,并发送 checkRequest
。我可以只指定 id,然后通过 id 搜索订阅的智能合约吗?我的意思是,智能合约可以在知道 id 的情况下访问订阅吗?智能合约是否可以接受与发送的 id 匹配的订阅并进行检查?
我无法理解永久保存在区块链上的数据(这个数据是什么时候保存的?)和保存在智能合约中的数据(智能合约有存储吗?)有区别吗?我知道这个问题很简单,但我听不懂。
作为交易的一部分传输的数据(方法和参数)存储在区块链中。合约处理交易的结果存储在每个节点的本地存储中。合约可以随时访问其数据。
合同示例如下:
- AddCustomer 方法以事务方式调用并添加用户
- GetCustomerById 方法被“本地”调用并通过其标识符显示用户数据
pragma solidity 0.5.0;
contract Gym
{
address Owner ;
struct Customer
{
bytes32 name ;
bytes32 surname ;
bytes32 start_date ;
bytes32 end_date ;
}
mapping (bytes32 => Customer) Customers ;
constructor() public
{
Owner = tx.origin ;
}
function AddCustomer(bytes32 id_, bytes32 name_, bytes32 surname_, bytes32 start_date_, bytes32 end_date_) public
{
Customers[id_]=Customer({ name: name_,
surname: surname_,
start_date: start_date_,
end_date: end_date_
}) ;
}
function GetCustomerById(bytes32 id_) public view returns (bytes32, bytes32, bytes32, bytes32 retVal)
{
return(Customers[id_].name, Customers[id_].surname, Customers[id_].start_date, Customers[id_].end_date) ;
}
}
为了介绍我的问题,我想举个例子。假设一位顾客想加入健身房。交易已发送并包含:
- 客户编号
- 姓名
- 开始日期
- 结束日期
智能合约接收交易并在健身房创建会员资格。这些数据保存在哪里?一段时间后,我想验证订阅是否已过期,并发送 checkRequest
。我可以只指定 id,然后通过 id 搜索订阅的智能合约吗?我的意思是,智能合约可以在知道 id 的情况下访问订阅吗?智能合约是否可以接受与发送的 id 匹配的订阅并进行检查?
我无法理解永久保存在区块链上的数据(这个数据是什么时候保存的?)和保存在智能合约中的数据(智能合约有存储吗?)有区别吗?我知道这个问题很简单,但我听不懂。
作为交易的一部分传输的数据(方法和参数)存储在区块链中。合约处理交易的结果存储在每个节点的本地存储中。合约可以随时访问其数据。
合同示例如下:
- AddCustomer 方法以事务方式调用并添加用户
- GetCustomerById 方法被“本地”调用并通过其标识符显示用户数据
pragma solidity 0.5.0;
contract Gym
{
address Owner ;
struct Customer
{
bytes32 name ;
bytes32 surname ;
bytes32 start_date ;
bytes32 end_date ;
}
mapping (bytes32 => Customer) Customers ;
constructor() public
{
Owner = tx.origin ;
}
function AddCustomer(bytes32 id_, bytes32 name_, bytes32 surname_, bytes32 start_date_, bytes32 end_date_) public
{
Customers[id_]=Customer({ name: name_,
surname: surname_,
start_date: start_date_,
end_date: end_date_
}) ;
}
function GetCustomerById(bytes32 id_) public view returns (bytes32, bytes32, bytes32, bytes32 retVal)
{
return(Customers[id_].name, Customers[id_].surname, Customers[id_].start_date, Customers[id_].end_date) ;
}
}